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).