Power of PowerShell and the SharePoint Snap-in

By | 2010-03-02

Recently I started to look into some more detail at PowerShell and the SharePoint 2010 Snap-in. As a small exercise I wanted to create something (somewhat) usefull.

I came up with a small site structure install script for SP2010.

First the source configuration, an xml, with the sites and subsites I wanted to created:

Next I wrote two helper function inside my PowerShell script:

First remove the existing site collection:

And then start reading the xml file and start creating a site collection

And add this to the top of your SP2010 PowerShell Script to always load the Snap-in.

You can download both files here: codeplex.com

3 thoughts on “Power of PowerShell and the SharePoint Snap-in

  1. Paul Cassidy

    you can simplify the code as xmldocument is a native type to powershell.


    [System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
    $file = resolve-path(“./sites.xml”)


    [xml]$xd = get-content (resolve-path “./sites.xml”)

  2. Paul Cassidy

    also you can replace all the $node.SelectNode with select-xml wich take a xpath expression to return the node or nodes you want. over all I really like the example of someone using the Sharepoint snapin as i am going to look into it soon.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.