When defining hierarchical structures, I personally prefer using an XML file, but there is still a place for the good old Comma-separated values (CSV) format. Firstly, it is easier to create and modify a CSV file – especially when using an application like Excel – and as the format has been around for a while, most people find it easier to read and understand. Despite its flaws, this must be the major reason why Microsoft decided to use CSV as the format for the Managed Metadata import file in SharePoint 2010.
Now we have the New-SPWeb PowerShell cmdlet introduced in SharePoint 2010, creating individual sites and sub-sites is easy enough to do without needing to visit the browser UI, but you still need to put in a bit of work if you are looking to create an entire site hierarchy using PowerShell.
To help you out, I have uploaded a “Create SharePoint Sites from CSV” PS1 script file to Codeplex for download. This script can be used to create multiple SharePoint sites in bulk from a CSV file and also set permissions on each site during creation.
It includes the following features:
- Choose any site from which to start creating sub-sites
- Create a full site hierarchy with sub-sites down to three levels from the start site
- Specify a site title, description, and URL name
- Specify whether to inherit parent site top navigation bar
- Specify whether to inherit parent site permissions
- If breaking permission inheritance, specify whether to add new permissions from scratch or by copying over permissions from the parent site and adding to those
- Assign site permissions to SharePoint groups, Active Directory users or Active Directory groups, specifying the permission level required
- Create the specified SharePoint group or Active Directory account in the site, if they do not already exist
You can download the script, documentation and an example CSV file at http://spcreatesitesfromcsv.codeplex.com. As always, I welcome any comments, suggestions, ideas or contributions for any new features if you have them.