Create Personal Sites with PowerShell – SharePoint 2013

If you want to create personal sites in bulk use the script below.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$site = new-object Microsoft.SharePoint.SPSite(“https://mysites.contoso.com”);
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); 

$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext); 
$AllProfiles = $ProfileManager.GetEnumerator();

#UserFormat is testUser001. Change as per your need.
$UserName = “contoso\tstUser0”

for ($i = 1; $i -lt 100; $i++)
{
    [string]$ActualUser = $UserName + “0” + “$i”
    #Write-Host $ActualUser
    if($ProfileManager.UserExists($ActualUser))
    {
        try
        {
            $profile = $ProfileManager.GetUserProfile($ActualUser)
            $AccountName = $profile[“AccountName”].Value
            Write-Host “Creating Personal Site for $AccountName” -ForegroundColor Yellow
            $profile.CreatePersonalSite()
            write-host “Personal Site has been created.” -ForegroundColor Green
        }
        catch
        {
             write-host “Personal Site Could not be created” -ForegroundColor Red
        }
    }
}

#List All Sites for the user
$Databases = @();
#UserFormat is testUser001. Change as per your need.
$UserName = “contoso\tstUser0”

for ($i = 1; $i -lt 100; $i++)
{
    [string]$ActualUser = $UserName + “0” + “$i”
    #Write-Host $ActualUser
    if($ProfileManager.UserExists($ActualUser))
    {
        try
        {
            $profile = $ProfileManager.GetUserProfile($ActualUser)
            $AccountName = $profile[“AccountName”].Value
            $DB = New-Object PSObject
            Add-Member -input $DB noteproperty ‘AccountName’ $AccountName
            Add-Member -input $DB noteproperty ‘Maximum’ $profile.PersonalSite.Url
            $Databases += $DB
        }
        catch
        {
             write-host “Personal Site Could not be created” -ForegroundColor Red
        }
    }
}

$Databases  | Out-File E:\TestUsers.csv
$Databases | Out-GridView

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s