Monday, October 18, 2010

Creating a Web Application with all out of the box templates

As a SharePoint Developer, I am sure you would think about creating one site collections for all available web templates for learning purpose. I used to to do this as first thing after I was done with configuring my server farm. After doing it several times manually, I thought of automating it and I am sharing my experience here…

Welcome to the world of SharePoint 2010 and PowerShell, it is not too difficult to do this.

Here are the steps to do so….

First, we need to create Web Application that will host several Site Collections (as many as the out of the box web templates). I took an approach of creating a .csv file as an input to my web application script. For now, I will have just one row in my WebApps.csv but you can have as many as you want!

Here is the script which access the WebApps.csv file and creates web application:

Add-PsSnapin Microsoft.SharePoint.PowerShell
Import-Csv -Path "WebApps.csv" -Delimiter "," | ForEach-Object {New-SPWebApplication -Name $_.Name -Port $_.Port -ApplicationPool  $_.ApplicationPool -ApplicationPoolAccount (Get-SPManagedAccount $_.PoolAccount)}
Write-host "Operation was executed successfully."
Read-Host

For the purpose of this exercise, my WebApps.csv looks like:

image

Next, I created a list of site collections and then provisioned each site collection with out of the box site template I used same .csv approach above and used following PowerShell script to create the site collections:

Add-PsSnapin Microsoft.SharePoint.PowerShell
Import-Csv -Path "Templates.csv" -Delimiter "," | ForEach-Object {New-SPSite -Url $_.Url -OwnerAlias "Sp10\Administrator" -Language 1033 -Template $_.Name -Name $_.Title }
Write-host "Operation was executed successfully."
Read-Host

As you can see we needed an official name of the site template if you want to create a site collection programmatically. And I used another SharePoint cmdlet to get list of appropriate site templates as shown below

Get-SPWebTemplate | where { ( $_.'IsHidden' -eq [System.Boolean]$False ) -and ( $_.'IsSubWebOnly' -eq [System.Boolean]$False ) }

The result of above command would look like:

image

I used above result to create a .csv file that I need, my final Templates.csv file looks like:

Lcid,Title,Name,url
1033,Team Site,STS#0,http://#YourWebAppUrl#
1033,Blank Site,STS#1,http://#YourWebAppUrl#/Sites/Blank
1033,Document Workspace,STS#2,http://#YourWebAppUrl#/Sites/DocWS
1033,Basic Meeting Workspace,MPS#0,http://#YourWebAppUrl#/Sites/BasicMeetWS
1033,Blank Meeting Workspace,MPS#1,http://#YourWebAppUrl#/Sites/BlankMeetWS
1033,Decision Meeting Workspace,MPS#2,http://#YourWebAppUrl#/Sites/DecisionMeetWS
1033,Social Meeting Workspace,MPS#3,http://#YourWebAppUrl#/Sites/SocialMeetWS
1033,Multipage Meeting Workspace,MPS#4,http://#YourWebAppUrl#/Sites/MeetWS
1033,Blog,BLOG#0,http://#YourWebAppUrl#/Sites/Blog
1033,Group Work Site,SGS#0,http://#YourWebAppUrl#/Sites/GroupSite
1033,Document Center,BDR#0,http://#YourWebAppUrl#/Sites/DocCenter
1033,Records Center,OFFILE#1,http://#YourWebAppUrl#/Sites/Records
1033,Business Intelligence Center,BICenterSite#0,http://#YourWebAppUrl#/Sites/BI
1033,Enterprise Search Center,SRCHCEN#0,http://#YourWebAppUrl#/Sites/EntSearch
1033,Publishing Portal,BLANKINTERNETCONTAINER#0,http://#YourWebAppUrl#/Sites/PubPortal
1033,My Site Host,SPSMSITEHOST#0,http://#YourWebAppUrl#/Sites/mysite
1033,Enterprise Wiki,ENTERWIKI#0,http://#YourWebAppUrl#/Sites/EntWiki
1033,Basic Search Center,SRCHCENTERLITE#0,http://#YourWebAppUrl#/Sites/BasicSearch
1033,FAST Search Center,SRCHCENTERFAST#0,http://#YourWebAppUrl#/Sites/FASTSearch
1033,Visio Process Repository,visprus#0,http://#YourWebAppUrl#/Sites/Visio

You may want to change the data in .csv file as needed!

Hope you enjoyed reading this and save some time by automating this process!

No comments:

Post a Comment