Sample PowerShell script to create web application and a site collection in SharePoint 2013

Just sharing a sample script that we are using to create a web application and a site collection of type publishing in it.

 

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell</pre>
# Set variables
$WebAppName = "MyAppPool"
$WebAppHostHeader = "servername"
$WebAppPort = "portnumber"
$url = "http://servername"
$WebAppAppPool = "MyAppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "domain\username"
$AuthenticationMethod = "NTLM"
$ap = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication -DisableKerberos

# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL $url -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -AuthenticationMethod $AuthenticationMethod -AuthenticationProvider $ap

# Set variables
$SiteCollectionName = "MySiteCollection"
$SiteCollectionURL = "http://servername:portnumber/"
$SiteCollectionTemplate = "BDR#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "LSS\lssspadmin"

# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Hope it helps ..


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s