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 {
[CmdletBinding()]
Param(
[Parameter(Mandatory)][System.String]$MySiteHostUrl
)
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;
}
else
{
#Skipping my sites with 0 items, but if you wanted to do something with them here's where you'd do it!
}
$spweb.Dispose()
}
Write-Output $MySites
}

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

Get-SPMySitesWithData -MySiteHostUrl http://my.contoso.com

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

Dog Food Conference 2015


RDspeakingOver the last two days, I’ve had the privilege of presenting at the Dog Food Conference for the 3rd time!

My presentations were focused more on the business user, or power user in both cases. The first day, I presented a new topic that I hadn’t yet shared with the world. Day 2 was one of my favorite sessions, an ECM talk based on a real-world scenario of leaving the file share mentality, and moving onto an ECM solution in SharePoint Server.

Continue reading…

New PowerShell Cmdlets in SharePoint 2016


I finally had some time to build my first SharePoint 2016 virtual environment, using the IT Preview bits w/ SQL Server 2014. Being a PowerShell guy, one of the first things I did – after running AutoSPInstaller of course – was open up PowerShell to start exploring the module snap-in. The first thing I wanted to take a look at was the number of cmdlets, because I knew there would be at least a few more than SharePoint 2013. Of course there are! There are actually 115 new cmdlets.

How did I figure that out (aside from checking out the aforementioned MSDN link)? Simple, run:

Get-Command -Module Microsoft.SharePoint.PowerShell | Measure-Object

Running the above returned 825. Eight hundred and twenty five commandlets! Very cool, but now I’m curious what are some of the new nouns that we administrators can run PoSh against? Taking a quick glance through the cmdlet list on MSDN, it was pretty obvious and expected to see lots of Azure, Office 365, and Project Server.

Sure, I can see an absolute need for those things. But out of curiosity, what do we have that’s not in those categories? Here are some of the commands that I am curious about, but haven’t been able to dig into yet. Also interesting is that the Help information for the cmdlets doesn’t appear to be baked into the snap-in yet:

  • Copy-SPDatabase
  • Copy-SPSideBySideFiles
  • Get-SPConnectedServiceApplicationInformation
  • Get-SPO365LinkSettings / Set-SPO365LinkSettings
  • Migrate-SPDatabase
  • Register-SPContentDatabase
  • Reset-SPSites
  • Set-SPServer
  • Start-SPService / Stop-SPService
  • Switch-SPSitesToNewDatabase
  • Upgrade-SPServer
  • Upgrade-SPWebApplication

Out of the list above, there are some interesting capabilities. I could guess as to what some of these might do, but instead – I’ll look into them some more with a plan of updating this post with some more detail. That is of course unless Microsoft (or other community contributors) releases some Help information on them.

Happy PowerShelling!