Powershell for creating mysite in SharePoint

Following script can be used to create mysite programatically using PowerShell

$site = new-object Microsoft.SharePoint.SPSite("http://mysite"); 
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); 

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

foreach($profile in $AllProfiles) 
{  
    $DisplayName = $profile.DisplayName
        $UserName = $profile.UserName
        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
   
    if($Accountname -match "domain\user")
    {
        $profile.CreatePersonalSite();
    }
}

No comments:

Post a Comment