PowerShell: Retrieve All Sites With or Without Personal Sites (MySites)

I love using the pipeline in PowerShell.  Recently I was in a situation where, if a PS script what a one-liner I didn’t have to submit it through the review/approval/change management process.  Its amazing what you can do in PowerShell in a single line of code!

Retrieve all site collections, for all web applications in the current farm.

$oSites = Get-SPWebApplication | Get-SPSite -Limit All

That one is pretty simple and I’m sure you’ve done it a bazillion times.  Lets add a little more and return all site collections, for all web applications except personal sites!

$oSites = Get-SPWebApplication | Get-SPSite -Limit All | where {($_.RootWeb.WebTemplateId -ne 54) -and ($_.RootWeb.WebTemplateId -ne 21)}

The only thing I’ve added here is a where clause that excludes sites with a template ID of 54 (personal site host) and 21 (personal sites).

Bob Mixon

Senior SharePoint Solution Architect, Senior Information Architect, 5-year Microsoft SharePoint MVP (2006, 2007, 2008, 2009, 2010). Family man, father, grandfather and cook.

You can read my entire profile here.

More Posts - Website

Follow Me:
TwitterLinkedIn

2 thoughts on “PowerShell: Retrieve All Sites With or Without Personal Sites (MySites)”

  1. Odd this isn’t working for me. It’s grabbing all the sites but still including MySites. I even added an exclusion for 22 and it’s picking them up, really… really… slowly…

Leave a Reply

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