SharePoint 2010: Create a new Web Application and Site Collection with Windows PowerShell

If you are nasty about creating always the same web application on SharePoint and you would like to automate it. Windows PowerShell is the solution.

Microsoft SharePoint 2010 is one of the new products which supports Windows Powershell commands. Its really easy to do the most tasks you do normally in the Sharepoint Central Administration with Windows Powershell.

# SharePoint cmdlets            
Add-PsSnapin Microsoft.SharePoint.PowerShell            
# Set variables            
$WebAppName = "TechNet Gokmania "            
$WebAppHostHeader = "TechNet.gokmania.com"            
$WebAppPort = 80            
$WebAppAppPool = "TechNetAppPool"            
# This User has to be a Sharepoint Manager Account            
$WebAppAppPoolAccount = "gokmania\WebAppTechnetAcc"            
$WebAppDatabaseName = "WSS_Content_Technet"            
$WebAppDatabaseServer = "srv-app-01\mssqlsp2010"            
            
# Create a new Sharepoint WebApplication            
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WWebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer
# SharePoint cmdlets             
Add-PsSnapin Microsoft.SharePoint.PowerShell             
# Templates             
# Name Title LocaleId Custom             
# ---- ----- -------- ------             
# GLOBAL#0 Global template 1033 False             
# STS#0 Team Site 1033 False             
# STS#1 Blank Site 1033 False             
# STS#2 Document Workspace 1033 False             
# MPS#0 Basic Meeting Workspace 1033 False             
# MPS#1 Blank Meeting Workspace 1033 False             
# MPS#2 Decision Meeting Work 1033 False             
# MPS#3 Social Meeting Works 1033 False             
# MPS#4 Multipage Meeting Work 1033 False            
            
# CA#0 Central Admin Site 1033 False             
# WIKI#0 Wiki Site 1033 False             
# BLOG#0 Blog 1033 False             
# SGS#0 Group Work Site 1033 False # Languages             
# Name Title             
# ---- -----             
# German 1031             
# English 1033             
# French 1036             
# Spanish 1034            
            
# Set variables             
$SiteCollectionName = "Homepage"             
$SiteCollectionURL = "TechNet.gokmania.com"             
$SiteCollectionTemplate = "STS#0"             
$SiteCollectionLanguage = 1033             
$SiteCollectionOwner = "gokmania\spfarm"            
            
# Create a new Sharepoint Site Collection             
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName            
            

References

Other Languages

This article is also available in the following languages: