Thursday, 14 October 2010

Create multiple SharePoint sites with permissions using a CSV file and PowerShell

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

CreateSitesFromCSV_Output

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.

17 comments:

  1. Hi,

    Is it possible to creates sites with powershell based on a csv file and custom site templates that are stored in the Solution gallery?.

    ReplyDelete
  2. Hi - you will need to use the script I refer to above in combination with this script from darko - http://mkdot.net/blogs/darko/archive/2011/02/17/create-web-from-custom-template-in-sharepoint-2010.aspx

    ReplyDelete
  3. Phil - Love the site. I'm using the script above to create a large number of sites. When the script gets to the permissions area it errors out anytime I attempt to add a new SPGroup (doesn't exist / create new). If I add a SPGroup that exist it does great. What do I need to look at?

    Thank you!

    ReplyDelete
  4. Hi, you could try adding the group to the site collection first as part of the script: http://get-spscripts.com/2011/02/add-sharepoint-or-ad-groupuser-to-all.html

    ReplyDelete
  5. Hi Phil,

    It is a great post. I'm having a problem when I'm using custom Site Template. Is there any way to use custom Site Template?

    Thanks
    Volmiro

    ReplyDelete
    Replies
    1. Hi Volmiro, I have already answered this question above....

      Delete
    2. Phil,

      My mistake, I think I checked the site before and I have just skipped because there are so many things on the site. :( I'm looking for it now. Thank You

      Again, it is a great post, and it is crucial to environment.

      Thanks

      Volmiro

      Delete
  6. Hi Phil

    Thanks for this great script! I did install the script and ran the commands per the instructions. However i get an error -> "The script has stopped because there has been an error". Any suggestions on what i am doing wrong ? Thanks!

    ReplyDelete
    Replies
    1. Forgot to mention above that the site gets created but the error shows up while trying to create the groups. I am not inheriting permissions from the parent site and trying to create new groups. Under Site permissions of the site, i only see the system account with full control. No other groups get created

      Delete
  7. Does anybody know if this works with SP2013?

    ReplyDelete
  8. I'm currently testing with SP2013, I had it working yesterday and managed to create ~20 sites each with 5 subsites, today it is refusing to do anything, getting error "The script has stopped because there has been an error" as soon as the script tries to run but I cannot determine why.

    ReplyDelete
  9. I found the reason - the instructions say to use "team site" as template name for -SiteTemplate, I found I had to use the corresponding code instead, for team site this is STS#0

    To find the codes for templates type:

    Get-SPWebTemplate | Sort-Object "name"

    in the Management Shell, this will list all codes for default templates.

    ReplyDelete
  10. With football we always have exciting games such as head soccer and head soccer unblocked and soccer heads and head soccer 2 or big head basketball big head soccer or head soccer will bring to everyone the good entertainment Best.

    ReplyDelete