Powershell: SharePoint 2007 vs 2010

It still amazes me the differences between writing powershell for SharePoint 2007 and SharePoint 2010. For example, look at the differences when you try to find the number of spwebs within a farm that have a template “STS#1”:


Add-PSSnapin “Microsoft.SharePoint.Powershell”

(Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite -Limit all| Get-SPWeb -Limit all | where{$_.WebTemplate -eq “STS” -and $_.WebTemplateId -eq “1”}).count



$total = 0

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

foreach($spService in $farm.Services) {

if($spService -is [Microsoft.SharePoint.Administration.SPWebService]) {

foreach($webapp in $spService.WebApplications) {

foreach($site in $webapp.Sites) {

foreach($web in $site.AllWebs) {

if($web.WebTemplate -eq “STS” -and $web.WebTemplateId -eq “1”) {

$total +=1







Write-host $total


One Response to Powershell: SharePoint 2007 vs 2010

  1. Kevin Kirkpatrick says:

    Interesting post! I think in 2007 you could also do a stsadm -o enumwebs and parse the xml if that was easier to you. That script would work as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: