Friday, 8 June 2012

Create SharePoint Sites with PowerShell

I had a request to provision ("fancy word for create") about 30 SharePoint sites today. And the lazy me went like "WTH", so i thought this is a good candidate for scripting(automation).

Here is what i did. I got an email with a list of the site names. something like this:

Site 1
Site 2
Site 3
Site 4 ....

So i quickly copied this into a text file, and imported it into an Excel sheet (am sure you can do that)

I then made a little bit of adjustment, and i ended up with something this.


Then i saved this as a csv file named sites.csv.

After that i opened my favourite text editor, and put this together.


$parentSiteUrl = "http://sharepointportal/"
$siteList = import-csv "sites.csv"
foreach ($site in $sitelist)
 {
  $siteUrl = $parentSiteUrl + $site.url
  $siteName = $site.sitename
  New-SPWeb –url $siteUrl -name $siteName -template STS#0 –AddToTopNav –UniquePermissions
 }


Then i saved the script above as createsite.ps1.  After that, i copied both files(createsite.ps1 & sites.csv) to the root drive C:\ of my sharepoint server.

I then opened the SharePoint 2010 Management Shell( as administrator) - shown below.


When the shell opened, I ran my script as shown below, and in a jiffy all the sites were created. Pretty Cool uhm.









No comments:

Post a Comment