Creating new SharePoint 2010 sites from templates with Powershell

Now that STSADM is gone it’s time to get one’s PowerShell skill(z) up to date…

Site templates in SharePoint 2010 are slightly different. To get a full listing of what you have access to use try the following:

Get-SPWebTemplate | select Name, Title

Note the name of each template…

Name Title
ACCSRV#0 Access Server Site
ACCSRV#2 Bugs
ACCSRV#3 Charitable Contributions
ACCSRV#5 Projects
BDR#0 Document Center
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
BLANKINTERNETCONTAINER#0 Publishing Portal
BLOG#0 Blog
CENTRALADMIN#0 Central Admin Site
CMSPUBLISHING#0 Publishing Site
ENTERWIKI#0 Enterprise Wiki
GLOBAL#0 Global template
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
OFFILE#0 (obsolete) Records Center
OFFILE#1 Records Center
OSRV#0 Shared Services Administration Site
PROFILES#0 Profiles
SGS#0 GroupBoard Workspace
SPS#0 SharePoint Portal Server Site
SPSCOMMU#0 Community area template
SPSMSITE#0 Personalization Site
SPSMSITEHOST#0 My Site Host
SPSNEWS#0 News Site
SPSNHOME#0 News Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSPORTAL#0 Collaboration Portal
SPSREPORTCENTER#0 Report Center
SPSSITES#0 Site Directory
SPSTOC#0 Contents area Template
SPSTOPIC#0 Topic area template
SRCHCEN#0 Enterprise Search Center
SRCHCENTERFAST#0 FAST Search Center
SRCHCENTERLITE#0 Basic Search Center
SRCHCENTERLITE#1 Basic Search Center
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
TENANTADMIN#0 Tenant Admin Site
vispr#0 Visio Process Repository
WIKI#0 Wiki Site

So with this knowledge you can do quite a bit. E.g. the below shows how to create a new site from template STS#0 which is a Team Site…

Write-Host
$SiteTitle = “My TeamSite (via PowerShell)”
$SiteUrl = “http://siteurl”
$SiteTemplate = “STS#0”
# make sure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
if ($snapin -eq $null) {
Write-Host “SharePoint SnapIn was not present. Loading…”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}
# create new site at target URL
Write-Host “Creating new site at” $SiteUrl
$NewSite = New-SPSite -URL $SiteUrl -OwnerAlias Administrator -Template $SiteTemplate -Name $SiteTitle
$RootWeb = $NewSite.RootWeb
# display site info to user
Write-Host “————————————-“
Write-Host “Site created successfully”
Write-Host “Title:” $RootWeb.Title -foregroundcolor Green
Write-Host “URL:” $RootWeb.Url -foregroundcolor Red
Write-Host “ID:” $RootWeb.Id.ToString() -foregroundcolor Blue
Write-Host “————————————-“