Use PowerShell to create a demosite for all the common used Web Templates in SharePoint 2013

In my previous article I provided a list of all the common used web templates in SharePoint 2013. For demo purposes it can be handy to spin up a copy of all these templates and later easy remove them. Using PowerShell we can accomplish this with the snippets provided below. Change the parameters under "Configuration" to match your own environment.

Create new site collections

This snippet will create a new site collection for each of the web templates.

[code language="powershell"]

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Configuration
$webApp = "http://intranet.contoso.com"
$managedPath = "sites"
$siteOwner = "contoso\sp_admin"
$languageId = 1033

# Create site collections for demo
Write "Create demo sites"
Start-SPAssignment -Global
New-SPSite "$webApp/$managedPath/demo-team-site" -Name "Team Site" -Template "STS#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-blog" -Name "Blog" -Template "BLOG#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-dev-site" -Name "Developer Site" -Template "DEV#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-project-iste" -Name "Project Site" -Template "PROJECTSITE#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-community-site" -Name "Community Site" -Template "COMMUNITY#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-document-center" -Name "Document Center" -Template "BDR#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ediscovery-center" -Name "eDiscovery Center" -Template "EDISC#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-records-center" -Name "Records Center" -Template "OFFILE#1" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-bi-center" -Name "Business Intelligence Center" -Template "BICenterSite#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ent-search-center" -Name "Enterprise Search Center" -Template "SRCHCEN#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-mysite-host" -Name "My Site Host" -Template "SPSMSITEHOST#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-community-portal" -Name "Community Portal" -Template "COMMUNITYPORTAL#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-basic-search-center" -Name "Basic Search Center" -Template "SRCHCENTERLITE#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-visio-process-rep" -Name "Visio Process Repository" -Template "visprus#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-pub-portal" -Name "Publishing Portal" -Template "BLANKINTERNETCONTAINER#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-ent-wiki" -Name "Enterprise Wiki" -Template "ENTERWIKI#0" -OwnerAlias $siteOwner -Language $languageId
New-SPSite "$webApp/$managedPath/demo-prod-catalog" -Name "Product Catalog" -Template "PRODUCTCATALOG#0" -OwnerAlias $siteOwner -Language $languageId
Stop-SPAssignment -Global

[/code]

Clean up and remove all the sites

This snippet will delete all the site collections created with the snippet above.

[code language="powershell"]

# Configuration
$webApp = "http://intranet.contoso.com"
$managedPath = "sites"
$siteOwner = "contoso\sp_admin"
$languageId = 1033

# Remove site collections
Remove-SPSite "$webApp/$managedPath/demo-team-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-blog" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-dev-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-project-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-community-site" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-document-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ediscovery-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-records-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-bi-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ent-search-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-mysite-host" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-community-portal" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-basic-search-center" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-visio-process-rep" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-pub-portal" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-ent-wiki" -Confirm:$false
Remove-SPSite "$webApp/$managedPath/demo-prod-catalog" -Confirm:$false

[/code]

Summary

This article demonstrated how easy we can create a copy of all the common used web templates in SharePoint for demo purposes, and later clean it up.