Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Create My Site for All Users in SharePoint using PowerShell

$
0
0
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.

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 SilentlyContinue

#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
}
}
}
BTW, I've tested this script in SharePoint 2013 to create mysite for all users!

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>