Create My Site Host Site Collection for SharePoint 2016 using PowerShell
My Site host is a prerequisite for configuring user profile service applications in SharePoint (Although you can provide My site host URL later, it’s a best practice to have it ready prior to creating a user profile service application). Creating My Site Host in SharePoint involves the following steps:
- Create a new web application for My Site
- Create “Personal” wildcard Managed Path for the web application
- Enable Self-Service Site Creation for the web app
- Create a root site collection using My Site Host template
- In User Profile Service Application, configure My Site Host location
How to Create My site host using PowerShell in SharePoint?
Let’s set up my site host for SharePoint in four steps. Here is my PowerShell script to create a Web application and My site Host Site Collection for SharePoint 2016:
Step 1: Create a Web application for My Site
Although you can use any existing web application for my site host in SharePoint 2016, let’s create a new web application to host my sites.
#PowerShell to create a web application
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Define Variables for Web Application Creation
$WebAppName = "Crescent Mysite"
$HostHeader = "mysite.Crescent.com"
$WebAppURL="https://" + $HostHeader
$WebAppPort = "80"
$ContentDBName = "Crescent_MySite_Content"
$AppPoolName = "MySite Web Application AppPool"
$AppPoolAccount = "Crescent\SP16_AppPool"
#Authentication Provider
$AuthProvider = New-SPAuthenticationProvider
#Check if Managed account is registered already
Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists"
$AppPoolAccount = Get-SPManagedAccount -Identity $AppPoolAccount -ErrorAction SilentlyContinue
if($AppPoolAccount -eq $null)
{
Write-Host "Please Enter the password for the App Pool Account..."
$AppPoolCredentials = Get-Credential $AppPoolAccount
$AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
}
#Create new Web Application
New-SPWebApplication -name $WebAppName -port $WebAppPort -hostheader $HostHeader -URL $WebAppURL -ApplicationPool $AppPoolName -ApplicationPoolAccount (Get-SPManagedAccount $AppPoolAccount) -AuthenticationMethod NTLM -AuthenticationProvider $AuthProvider -DatabaseName $ContentDBName
Step 2: Create “Personal” Managed Path
#Create Managed Path for My Site Web application
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Define Parameters
$WebAppURL = "https://mysite.Crescent.com"
$WebApp = Get-SPWebApplication $WebAppURL
#Add Managed Path
New-SPManagedPath "Personal" -WebApplication $WebAppURL -Explicit
Step 3: Enable Self Service Site Creation for My Site Web Application
#Enable Self service site creation
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Set Parameters
$WebAppURL = "https://mysite.Crescent.com"
$WebApp = Get-SPWebApplication $WebAppURL
#Enable Self Service Site collection
$webApp.SelfServiceSiteCreationEnabled = $true
$webApp.RequireContactForSelfServiceSiteCreation = $false
$webApp.Update()
Step 4: Create My Site Host Site Collection
As a final step, let’s create a SharePoint Mysite host site collection using Mysite host template.
#Create My Site Host Site collection
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Set Parameters for My Site Host Site Collection Creation
$WebAppURL = "https://mysite.Crescent.com"
$FarmAdminAccount="Crescent\SP16_Farm"
$Contentdatabase="Crescent_MySite_Content"
$WebApp = Get-SPWebApplication $WebAppURL
#Create My Site Host site collection
New-SPSite -Name "My Site Host" -Url $WebAppURL -Template "SPSMSITEHOST#0" -OwnerAlias $FarmAdminAccount -ContentDatabase $Contentdatabase
Once all these steps are completed, confirmed from SharePoint Central Admin, my site host web application and site collections are listed.
SharePoint 2016 my site host URL is ready! Now what? Set My Site Host location in your user profile service application! If you want to change mysite host URL, refer to How to change My site host location in SharePoint?
hello
i would lik to pre-provsionning all users via script power
can you help me please ?
Here you go: Create My Site for All Users in SharePoint using PowerShell