SharePoint My Sites are automatically created when the first time Users click on the My Content link. However, To promote the usage of SharePoint social, we deiced to pre-create SharePoint My sites for all users.
SharePoint: Create Mysite for all users using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function Create-MySite($MySiteHost, $UserAccount)
{
#Get Objects
$ServiceContext = Get-SPServiceContext -site $MySiteHost
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
#Check if user Exists
if ($UserProfileManager.UserExists($UserAccount))
{
#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserAccount)
#Check if User's My site is Cretaed already
if($UserProfile.PersonalSite -eq $Null)
{
$UserProfile.CreatePersonalSite()
write-host "My Site Created Successfully for the User!" -f Green
}
}
else
{
write-host "$($UserAccount) Not Found!" -f Red
}
}
Create-MySite "https://mysite.crescent.com" "Crescent\Salaudeen"
SharePoint: Create Mysite for all users using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinueBTW, I've tested this script in SharePoint 2013 to create mysite for all users!
#Variables
$MySiteHost = "https://mysite.crescent.com"
#Get Objects
$ServiceContext = Get-SPServiceContext -site $MySiteHost
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
#Get All User Profiles
$UserProfiles = $UserProfileManager.GetEnumerator()
#Iterate through each profile
foreach ($Profile in $UserProfiles)
{
if($Profile.PersonalSite -eq $Null)
{
#Check if User's My site is Cretaed already
if($Profile.PersonalSite -eq $Null)
{
#$UserProfile.CreatePersonalSite()
write-host "My Site Created Successfully for the User:" $Profile["AccountName"] -f Green
}
else
{
write-host "My Site Already Exists for the User:" $Profile["AccountName"] -f Red
}
}
}