I am trying to create My Site Host Site Collection through PowerShell scripts. I am able to create a new web application, set Self Service Site Creation Enabled property on it, Create a new Permission Policy for creating subsites, Associate this Permission Policy to Everyone user in User Policy for this web application, Create a new Managed Path and also create a new Site Collection, all through PowerShell. Now, in the User Profile Service Application, there is a link to Setup MySites. Here we associate the user profile service application with the my site configuration. I need to be able to achieve these steps also through PowerShell, but not able to. I tried to check the properties / methods on the User Profile Service Application and also its Proxy, but couldn't find anything. Can anyone please provide the scripts for this?
2 Answers
Edit - Adding code here for quick reference as per comments.
Add - PSSnapin Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue
$MySiteurl = "https://SPMY.Gowtham.com"
$ServiceContext = Get - SPServiceContext - site $MySiteHost
$UserProfileManager = New - Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)# Retrive all user Profiles
$UserProfiles = $UserProfileManager.GetEnumerator()# Loop through each profile
foreach($Profile in $UserProfiles)
{
if ($Profile.PersonalSite - eq $Null)
{
if ($Profile.PersonalSite - eq $Null)
{#
$UserProfile.CreatePersonalSite()
write - host "My Site Profile Created Successfully for :"
$Profile["AccountName"] - f Green
} else
{
write - host "Site Already Exists for the User:"
$Profile["AccountName"] - f Red
}
}
}
below are some links which might be useful.
https://code.msdn.microsoft.com/office/Create-a-MySite-for-all-8bc8acc7 https://vigneshsharepointthoughts.com/2015/08/26/powershell-command-to-manually-create-a-users-my-site-in-sharepoint/ http://matthewyarlett.blogspot.com/2014/06/script-creating-sharepoint-user-mysites.html
-
Please don’t add just a link as answer to a question. If the link breaks, the answer you provided will not be useful for future visitors. Provide an answer of your own and use the link as reference. If needed, you can block quote the content from your link. More information is found in our help center, especially How do I write a good answer– Benny Skogberg ♦Nov 4, 2016 at 8:50
This has been answered here. Please find the link below