This is the second part of a Post started by Mattias Karlsson. Click Here to See Part One
Following on Mattias lead, I’m going to describe how to build a script that automatesthe creation of 700+ Sites in sharepoint. The scenario is well described by Mattias so I’m just going to dig directly into the code. The first thing we want to consider is the Csv file. Since we work in a Swedish / Finnish Company, there are alot of funny looking characters and non-friendly names that could cause a problem in sharepoint. So step one is getting rid of all funnies. This is a perfect job for the -replace operator.
Importing the csv File to PowerShell is done through the Import-Csv CmdLet, as soon as we have imported the Csv file, we can edit each line in it.
There are basically 2 steps that we want to do in Sharepoint, Adding information to a Directory List and creating Sites. The Directory list can be treated in the same way as we altered Custom Lists in this post.
The only “new” item that we want to add now is the URL, which takes 2 arguments, URL and Description.
The Connections to Sharepoint are done in the same way as in previous examples, just make sure to change which list you want to connect to and where your SiteDirectory is.
Creating Sites is described in this post. What’s new in this example is the Template that we want to use. In order to tell SharePoint that we want to build our sites based on a template file, we have to add the template as an argument to the Add() method.
Now that we have gone through all the techniques set and ready, let’s put it all togheter in a ps1 script. The script consists of 3 functions, one Help function that describes how to use the ps1 script, one Csv function that imports the csv file and prepares it and finally a function that adds all data to sharepoint.
Click here to download the Script.
Click here to download a template Csv File
[?]
Pingback: Batch creation of SharePoint sites « My SharePoint of view