locked
PowerShell script to Create My Site Host Site Collection RRS feed

  • Question

  • 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?

    Ven

    Friday, November 4, 2016 7:12 AM

Answers

  • Sorry for the late response. I had already figured this. Anyway, thanks for the reply. Also, I don't have any site collection URL. So, I used the below construct. Moreover, I need a few other settings also. Below is the full code.

     $site = new-object Microsoft.SharePoint.SPSite($webAppURL)
     $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site) 
     $ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext) 
     $ProfileManager.MySiteHostUrl = $webAppURL
     $ProfileManager.PersonalSiteInclusion = "personal"
     $ProfileManager.PersonalSiteReaders = "c:0!.s|windows,c:0(.s|true"
     $site.Dispose()


    Ven


    • Edited by Venh Friday, November 4, 2016 9:40 AM
    • Marked as answer by Venh Friday, November 4, 2016 9:40 AM
    Friday, November 4, 2016 9:25 AM
  • Hi Venh,

    You can use the below code to set the My Site Host URL in the User Profile Service Application using the below code:

    Add-PSSnapin Microsoft.Sharepoint.Powershell 
    
    $AnySiteCollectionUrl = "http://AnySPSite/"
    $site = Get-SPSite $AnySiteCollectionUrl
    
    $context = Get-SPServiceContext($site) 
    $pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 
    
    Write-Host "previous My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
    
    $pm.MySiteHostUrl = ""
    $pm.MySiteHostUrl = "http://myspserver/"
    Write-Host "new My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
    
    $site.Dispose()
    
    Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
    Read-Host

    More Info:

    http://fangdahai.blogspot.in/2013/01/how-to-change-my-site-host-url.html

    Thanks,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    • Marked as answer by Venh Friday, November 4, 2016 9:53 AM
    Friday, November 4, 2016 8:15 AM

All replies

  • Hi Venh,

    You can use the below code to set the My Site Host URL in the User Profile Service Application using the below code:

    Add-PSSnapin Microsoft.Sharepoint.Powershell 
    
    $AnySiteCollectionUrl = "http://AnySPSite/"
    $site = Get-SPSite $AnySiteCollectionUrl
    
    $context = Get-SPServiceContext($site) 
    $pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 
    
    Write-Host "previous My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
    
    $pm.MySiteHostUrl = ""
    $pm.MySiteHostUrl = "http://myspserver/"
    Write-Host "new My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
    
    $site.Dispose()
    
    Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
    Read-Host

    More Info:

    http://fangdahai.blogspot.in/2013/01/how-to-change-my-site-host-url.html

    Thanks,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    • Marked as answer by Venh Friday, November 4, 2016 9:53 AM
    Friday, November 4, 2016 8:15 AM
  • You'll want to do something like this:

    $ups = New-SPProfileServiceApplication -Name "User Profile Service" -ApplicationPool "SharePoint default AppPool" -ProfileDBServer "DB server name or alias" -ProfileDBName "ProfileDB" -SocialDBServer "DB server name or alias" -SocialDBName "SocialDB" -ProfileSyncDBServer "DB server name or alias" -ProfileSyncDBName "SyncDB"
    
    New-SPProfileServiceApplicationProxy -Name "User Profile Service Proxy" -ServiceApplication $ups 

    Reference here


    If this is helpful please mark it so. Also if this solved your problem mark as answer.



    • Edited by taylor.l Friday, November 4, 2016 8:23 AM
    Friday, November 4, 2016 8:22 AM
  • Sorry for the late response. I had already figured this. Anyway, thanks for the reply. Also, I don't have any site collection URL. So, I used the below construct. Moreover, I need a few other settings also. Below is the full code.

     $site = new-object Microsoft.SharePoint.SPSite($webAppURL)
     $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site) 
     $ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext) 
     $ProfileManager.MySiteHostUrl = $webAppURL
     $ProfileManager.PersonalSiteInclusion = "personal"
     $ProfileManager.PersonalSiteReaders = "c:0!.s|windows,c:0(.s|true"
     $site.Dispose()


    Ven


    • Edited by Venh Friday, November 4, 2016 9:40 AM
    • Marked as answer by Venh Friday, November 4, 2016 9:40 AM
    Friday, November 4, 2016 9:25 AM
  • Thats Cool Venh. Thanks for Sharing.

    Regards,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    Friday, November 4, 2016 9:49 AM
  • But since you had also posted the answer, I will mark it. Thank you once again for your help.

    Ven

    Friday, November 4, 2016 9:53 AM
  • Hi Venh,

    Thanks for your sharing. Your solution will benefit many other users.

    If you have any other questions or concerns, please do not hesitate to contact us. It is always our pleasure to be of assistance.

    Have a nice day!

    Best Regards,

    Lisa Chen


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, November 7, 2016 1:45 AM