• home
    • news & events
    • blog
  • über uns
    • projekte und referenzen
    • partner
    • produkte & technologien
    • offene jobs / stellen
    • veröffentlichungen
  • dienstleistungen & services
    • software design & architektur
    • software entwicklung
    • beratung / consulting
    • training, kurse und workshops
  • angebote
    • quick-starts
    • trainings und kurse
    • modulare sharepoint 2010 workshops
  • kontakt
"Wir sprechen SharePoint."
In Code und Klartext.
Seit über 100 Jahren.
Diesen Blog abonnieren
Subscribe in NewsGator Online Add to My AOL
Add to Google Reader or Homepage Add to netvibes

Aktuelle Posts

Ribbon Designer für SharePoint und Office365
Mapping Boolean Properties in a Custom Nintex Workflow Action
SharePoint Designer, Literals und das __designer:Preview Ärgernis
Spellcheck: Anpassen (Customizing) des Content Editors
Access Services - the Big Picture

Archiv

Mai 2012 (1)
April 2012 (5)
März 2012 (5)
Februar 2012 (7)
Januar 2012 (4)
Dezember 2011 (2)
November 2011 (10)
September 2011 (3)
August 2011 (7)
Juli 2011 (1)
Juni 2011 (3)
Mai 2011 (6)
April 2011 (5)
März 2011 (8)
Februar 2011 (8)
Januar 2011 (4)
Dezember 2010 (5)
November 2010 (7)
September 2010 (6)
August 2010 (2)
Juli 2010 (11)
Juni 2010 (13)
Mai 2010 (11)
April 2010 (4)
März 2010 (6)
Februar 2010 (2)
Januar 2010 (6)
Dezember 2009 (4)
November 2009 (13)
Oktober 2009 (17)
September 2009 (2)
Juli 2009 (2)
März 2009 (2)
Januar 2009 (1)

1stQuad ist Microsoft Certified Gold Partner und bietet SharePoint und .NET Produkt- und Projekt-Kompetenz, -Erfahrung und -Know-How für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Schweiz sowie Deutschland und Östereich.
1stQuad ist MatchPoint Partner und bietet MatchPoint Produkt- und Projekt-Kompetenz, -Erfahrung und -Know-How für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Schweiz sowie Deutschland und Östereich.
1stQuad ist Nintex Partner und bietet Nintext SharePoint Workflows Produkt- und Projekt-Kompetenz, -Erfahrung und -Know-How für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Schweiz sowie Deutschland und Östereich.
1stQuad ist Balesio Gold Partner und bietet SharePoint FILEMinimizer Produkt- und Projekt-Kompetenz, -Erfahrung und -Know-How für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Schweiz sowie Deutschland und Östereich.
1stQuad Solutions ist Kentico Certified Solution Partner und bietet Produkt- und Projekt-Kompetenz, -Erfahrung und -Know-How für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Schweiz sowie Deutschland und Östereich.
© 2011 1stQuad Solutions
Alle Rechte vorbehalten
> Impressum
Wir bieten Microsoft SharePoint und .NET Projekt- und Produkt-Know-how, Kompetenz und Erfahrung für Entwicklung, Architektur, Beratung, Schulung, Training und Kurse in Zürich, Bern, Basel, Schweiz sowie Deutschland und Östereich.

Blog > Februar 2012

Using PowerShell Script to Automate Testing of all Site Templates

If you have features or look and feel which can be applied to sub-sites, then you will want to make sure that they are compatible with all the relevant site templates available. This means creating a suitable sub-site for each site template, a task ideally suited for scripting.

Veröffentlicht am 08.02.2012 17:02:54 von Simon Sebright mit 0 Kommentar(en)

Powershell Snapin and the Commandlets

Using the snapin for SharePoint 2010 (preloaded when you use the SharePoint Management Shell), we can base our approach on two key commandlets.  First of all, to create a sub-site, we use New-SPWeb.  An example call is shown here:

$web = New-SPWeb -Template STS#0 -Name MySubSite http://MyWebApp/Sites/MySiteCollection/MySubSite -AddToQuickLaunch

For a particular list of site templates, we can implement an array of name/title pairs, and iterate over them:

$siteDetails = (("STS#0", "STSNum0"),

("STS#1", "STSNum1"),

("STS#2", "STSNum2"),

("MPS#0", "MPSNum0"),

("MPS#1", "MPSNum1"),

("MPS#2", "MPSNum2"),

("MPS#3", "MPSNum3"),

("MPS#4", "MPSNum4"))

function Create-Sites($root)

{

      $site = New-Object Microsoft.SharePoint.SPSite ($root)

       Write-Host "Processing site: " $site.Url

 

      $siteDetails | foreach {

            Write-Host $_[0]

            $web = New-SPWeb -Template $_[0] -Name $_[1]  -Url $($root + "/" + $_[1]) -AddToQuickLaunch

      }

 

      $site.Dispose()

}

 This of course relies on us knowing the names of the site templates and choosing a suitable name/url for the sites.  The # character is not allowed in urls, so we have to change that – note the use of “Num” in the above array.  This can be easily done in bulk with a text editor using the regular expression:

 {.*}#{.*}

And a replace expression:

("\1#\2", "\1Num\2"),

Now for the second commandlet: Get-SPWebTemplate. If we just call that in the SharePoint Management Shell, we get a list of all the templates with Name, Title, etc.:

Get-SPWebTemplate results in Command Window

Note that the results are per language – so it appears at first as though there are duplicates.  We can pipe these results into a foreach loop to process each in turn:

function Create-SubSites($root)

{

      $site = New-Object Microsoft.SharePoint.SPSite ($root)

     

      Write-Host "Processing site: " $site.Url

           

      Get-SPWebTemplate | foreach {

            Write-Host $_.Name

            $web = New-SPWeb -Template $_.Name -Name $_.Title $($root + "/" + $_.Title) -AddToQuickLaunch

      }

     

      $site.Dispose()

}

 

This will fail for a couple of templates because the Title is not always suitable for a well-formed url, and also there are duplicates.  In order to get round this, a find/replace on the # in Name will suffice.

Also note that certain templates will require that you site collection has certain services and features available (for example, the Access-based templates (ACCSRV#0, etc.)).

Cleaning up and Re-running the Script

You may wish to run this script again on the same site collection, in which case it will fail because the sites already exist.  This means you will have to delete all your subsites first.  This is slightly complicated by the fact that some templates create sub-sub-sites (e.g. Collaboration Portal, Publishing Portal).  A simple recursion is listed below, this could be done to any required depth with a proper recursive function.

 

function Clean-SubSites($root)

{

      $site = New-Object Microsoft.SharePoint.SPSite ($root)

     

      Write-Host "Cleaning site: " $site.Url

     

      $site.Rootweb.Webs | foreach {

            Write-Host "Deleting" $_.Url

            $_.Webs | foreach {$_.Delete()}

            $_.Delete()

            $_.Dispose()

      }

     

      $site.Dispose()

     

}

Putting it all Together

Let’s put that all together in a script which takes a parameter – the url of your site collection:

param($url)


$snapin = Get-PSSnapin -Name Microsoft.SharePoint.PowerShell

if($snapin -eq $null) { Add-PSSnapin Microsoft.SharePoint.PowerShell }


function Clean-SubSites($root)

{

      $site = New-Object Microsoft.SharePoint.SPSite ($root)

      Write-Host "Cleaning site: " $site.Url

     

      $site.Rootweb.Webs | foreach {

            Write-Host "Deleting" $_.Url

            $_.Webs | foreach {$_.Delete()}

            $_.Delete()

            $_.Dispose()

      }

     

      $site.Dispose()

     

}

 

function Create-SubSites($root)

{

      $site = New-Object Microsoft.SharePoint.SPSite ($root)

      Write-Host "Processing site: " $site.Url

      Get-SPWebTemplate | foreach {

            Write-Host $_.Name

            $web = New-SPWeb -Template $_.Name -Name $_.Title $($root + "/" + $_.Name.Replace("#", "Num")) -AddToQuickLaunch

      }

     

      $site.Dispose()

}

Clean-SubSites($url)

Create-SubSites($url)


Enjoy!


Kommentar
Dieser Blog-Eintrag wurde noch nicht kommentiert.
Kommentar hinterlassen



 Security code
Zurück, Seite drucken