SharePoint Management Done Successfully with PowerShell

default post thumbnails

SharePoint Management is a big topic and, in all honesty, can cover a lot of spheres, even more so with the cloud. If you’ve worked with SharePoint, by now, you’ve probably realized that you can’t do much from the interface.

Don’t get me wrong: there are quite a few options in Settings as well as the Admin center, and that’s not even counting features available on Microsoft 365. But you can go a little further and manage SharePoint using PowerShell.

PowerShell and SharePoint Management Shell explained

If you’re working with anything in the Microsoft space, you’ve probably heard about PowerShell.

Do you remember the Command Prompt on your computer? It allowed you to execute commands that weren’t always available in the interface of your Windows but also allowed you to save and script them to run when you wanted.

PowerShell is essentially the same, but with a lot more power. You can type your commands there and see the results just like before. However, the benefit is that you can add your own “Shells” or set commands to enable the user to do more.

As an example, if you look at SharePoint as a product, Microsoft added SharePoint-specific commands to the regular PowerShell available on Windows. They’re called Management Shell, which enables you to manage SharePoint effectively.

Even here at ShareGate, we created our own list of commands to help you script and schedule your actions and made them available in PowerShell. There’s really a lot we can do with PowerShell when we start to think about it, and not only for SharePoint management.

Get started with the SharePoint Management Shell

Once you know how it works, you’ll realize that there isn’t much to it. I won’t go into much detail about scripting or complex scenarios, but I want to show you what you can do.

If you want to learn PowerShell from the start, I recommend you check out this interesting guide that may help you get started. Also, you’ll want to look at the official PowerShell product documentation.

To start managing your SharePoint, make sure you open the Management Shell and not just PowerShell since the commands you need won’t be available.

Management Shell

If you want to get an idea of what you can do, the SharePoint Management Shell comes with a few commands to help you.

Get-Command -Module “Microsoft.Online.SharePoint.PowerShell”

This will give you the list of commands available for managing SharePoint. As you know, PowerShell can manage anything, so by sticking to the Management module, we can see what we can do.

Another way for you to get started and see what’s available is by browsing through the Index of Windows PowerShell cmdlets for SharePoint, both in Microsoft 365 and SharePoint Server. Combined with the built-in PowerShell ISE, you can probably get started quickly.

And, of course, the PowerShell Command Builder is a fun way to get started building your commands if you like. But I’ll be honest: it’s something I found to be more cool than useful.

Let’s begin with a simple notion like getting the Site Collections.

Get-SPOSite

Simple enough, but how do I find out more information about these Site Collections? Your best friend is the Get-Member command that shows you what’s available in the current command you’re using.

Get-Member

You’ll see all the results show up, but their differentiator is the “Member Type,” and in this case, we’ll see some results as “Method” and some as “Property”. And that, my friends, is how you unleash the power of the SharePoint Management Shell!

Get Member

Essentially, “Methods” are what you can do to the object in your command, and in this case, it would be Site Collections we get from the result of Get-SPSite. For example, you can use the Delete method to delete the Site Collections returned.

Then you have “Property” that gives you the values for each of the possible properties of the object you asked for. Since we’re looking at Site Collections, we can see that there’s an “Owner” property that will return the Site Collection Owner of the results returned.

After that, it’s a matter of spending some time and exploring what’s available to see how you can apply your SharePoint Management rules and policies with PowerShell.

Manage your SharePoint Site Collections by first building an inventory

Manage SharePoint Site Collections by building an inventory

When we’re looking for complete SharePoint management capabilities, sometimes it can be as simple as getting the information we need out of SharePoint, building reports.

Get-SPWebApplication https://portal.contoso.com | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV C:sharepointinventory.csv -NoTypeInformation

But as mentioned, we can literally go through the properties and get all the information we could ever want out of SharePoint.

Get-SPSite “http://portal.contoso.com/sites/test” | Select-Object url, owner, @{Expression={$_.Usage.Storage}}, @{Expression={$_.Audit.AuditFlags}}, readonly, LastContentModifiedDate, @{Express={$_.QuotaStorageMaximumLevel}}

The command above will get me some pretty useful information on my Site Collection as well.

Another very important command to help you with your management is the Get-SPDeletedSite command to show you all deleted Site Collections and even recover them if you need to.

Site Collections without modified content for 12 months

Site Collections without modified content

To keep a clean environment, or just to stay on top of things, it could be interesting to see which Site Collections have nothing new or modified for the last 12 months. Once again, with the SharePoint Management Shell and a few lines and filters on the properties we see, we can get the results we need.

Get-SPSite -Limit All | Where-Object {$_.LastContentModifiedDate -le ((get-date).AddMonths(-12))} | select url, lastcontentmodifieddate

In this case, if the Site Collection’s Last Content Modified Date is less than today’s date minus 12 months, it’ll show up as one of the results. However, this property isn’t the best option for building these kinds of reports, since the content may be modified by features or other things running in SharePoint.

You can even add the property “Owner” to the command above and have their names and emails show up so you can contact them and see if it’s ok to delete. Let’s change the “select” of the last command to the following:

select url, lastcontentmodifieddate, @{Expression={$_.owner.name}}, @{Expression={$_.owner.email}}

Find Lists and Libraries in SharePoint with versioning disabled

SharePoint Lists and Libraries with versioning disabled

One of the best features of SharePoint is its versioning in lists and libraries. Enabling users to view, compare and even restore a previous version of a document is a great asset to document management.

Here’s a way to find out if there are any lists and libraries that do not have it enabled:

$sites.lists | Where {$_.enableversioning -eq $False} | select title, basetype, enableversioning, rootfolder, parentweb, parentweburl | sort parentweburl | Format-Table

The $sites variable essentially gets all the Sites within the Site Collections I want.

SharePoint Management with PowerShell takes time

If you have the time to sit down and explore all the Get-Member properties and methods available and test them, I’m convinced you will enjoy using it to manage your SharePoint. The examples above are just some of the many possibilities offered when using this Management Shell.

Whether you want to build an inventory that includes details like storage and quota usage as well as who’s the owner or find libraries with custom permissions, almost everything is possible.

The only downside I can mention to using PowerShell for SharePoint management is the time we have to invest when we’re not familiar with it or don’t have any scripting or coding background.

Don’t forget to try these PowerShell script examples to expand your knowledge on how you can easily automate admin tasks.

What PowerShell commands do you use most often for your SharePoint management tasks? Tell us in the comments!

What did you think of this article?

Recommended by our team

Getting started is easy

Try ShareGate free for 15 days. No credit card required.

Hosts 1

LIVE VIRTUAL EVENT RISE UP: Ignite your M365 tenant migration playbook