How to Create a Site Collection Using Windows PowerShell
This topic provides guidance on how to use Microsoft Windows PowerShell to create a Microsoft SharePoint 2010 site collection within your SharePoint 2010 Web application.
Prerequisites
See Using Windows PowerShell for SharePoint 2010 Commerce Deployment for a list of variables and sample values that may be used in sample scripts provided in this topic.
A Web application must already exist.
To create a site collection using Windows PowerShell
The following is a sample Windows PowerShell script that creates a site collection within a SharePoint 2010 Web application. The script sets the AnonymousState property so that anonymous users can browse the Internet after the site collection is created.
Important Note: |
---|
The SharePoint Commerce Services Extensibility Kit provides distinct template files for each supported version of SharePoint 2010. For SharePoint Server 2010, the template file is MicrosoftCommerceSPServerStorefrontSite.wsp. For SharePoint Foundation 2010, the file name is MicrosoftCommerceSPFoundationStorefrontSite.wsp. Make sure your script references the appropriate template. The following script sample uses the template provided for use with SharePoint Foundation 2010. |
Note
For information about creating non-root site collections, see Non-Root Site Collections.
$webTemplates = Get-SPWebTemplate
if($webTemplates)
{
foreach ($webTemplate in $webTemplates)
{
# Write-Host "--> " $webTemplate.Name
if($webTemplate.Name -like "*CSStorefrontSite#0")
{
Write-Host "Creating Root Site Collection " $webTemplate.Name
New-SPSite -Url $WebSiteUrl -OwnerAlias $SiteOwner -Name "Store" -Template $webTemplate
Write-Host "Root Site Collection created ..."
}
}
}
$site = Get-SPSite $WebSiteUrl
if($site)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site.AllWebs[0].AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::"On";
$site.AllWebs[0].Update();
}
Note
If your script references a site template that does not already exist, you may have to re-open a new Windows PowerShell window to run your script in two sequences.
See Also
Other Resources
Using Windows PowerShell for SharePoint 2010 Commerce Deployment
Walkthrough: Deploying SharePoint 2010 Commerce Solution in a Two-Tier Topology
Walkthrough: Deploying a SharePoint 2010 Commerce Solution in a Three-Tier Topology