Determine SharePoint 2013 My Site Usage with PowerShell

As a SharePoint consultant, I frequently encounter situations where a client / customer has My Sites deployed. However, nearly as frequently I’ll come across situations where they’re really not sure how many they have, who is actually using them, or if anybody is using them. While there are certainly GUI approaches to determining usage, PowerShell is a great, quick way to analyze an environment. Using the SharePoint Server Object Model, we can easily obtain this information.

Without further ado, here is a quick and dirty PowerShell function which can be used to determine My Site usage. Note: this will only tell you about My Sites with documents, feel free to tweak it for your usage:

function Get-SPMySitesWithData {
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction stop;
[Object[]] $MySites = New-Object PSObject
$webapp = Get-SPWebApplication $MySiteHostUrl
$webapp.Sites | ForEach-Object {
$spweb = $_.RootWeb
$docsLib = $spweb.Lists["Documents"]
$siteSize = $spweb.Site.Usage.Storage/1MB
$siteSizeInMb = "{0:N2}" -f $siteSize
if($docsLib.Items.Count -gt 0)
[Object] $mysite = New-Object Management.Automation.PSObject;
$mysite | Add-Member -MemberType NoteProperty -Name SiteUrl -Value $spweb.Url
$mysite | Add-Member -MemberType NoteProperty -Name ItemCount -Value $docsLib.Items.Count.ToString()
$mysite | Add-Member -MemberType NoteProperty -Name "SiteSize(MB)" -Value $siteSizeInMb
$MySites += $mysite;
#Skipping my sites with 0 items, but if you wanted to do something with them here's where you'd do it!
Write-Output $MySites

To run it, simply treat it like a normal SharePoint PowerShell Cmdlet:

Get-SPMySitesWithData -MySiteHostUrl

And here’s what the object looks like once the function is complete:


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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 )

Connecting to %s