SPTechCon The SharePoint and Office 365 Conference Logo

Getting started with the Patterns and Practices PowerShell for SharePoint Online

Getting started with the Patterns and Practices PowerShell for SharePoint Online

by: Shane Young

Hopefully by now you have fully embraced PowerShell as part of your SharePoint life. Why? Because it is magical no matter what your role is:

And honestly, that is just grazing the surface of what you can do. If you haven't accepted PowerShell into your life yet, then STOP, clear your calendar and watch this video on getting started.

Microsoft's PowerShell for SharePoint Online
After enjoying a lifestyle where I could do anything I wanted to with SharePoint on-prem, I found it very jarring the first time I tried to use PowerShell with SharePoint online (SPO). There are currently only 56 cmdlets compared to the 800+ that come with SharePoint Server on-prem; that is a sad panda. And honestly, when trying to use them, you realize they don't even really do 56 helpful things.

With all of that said, I still believe everyone should install the four packages that make up the Office 365 PowerShell cmdlets that SharePoint Online is included in. If you haven't installed them, there is a video for Installing PowerShell for Office 365.

So, what are you supposed to do? The answer is you need to be thankful that the Patterns and Practices (PNP) team decided to embrace fixing the problem.

Patterns and Practices Team
If you haven't checked out their website, I highly recommend you do. It is a group of Microsoft consultant who got together in 2013 to help developers cope with the transition from O365 dedicated to O365 multi-tenant. And while I find developer stuff dreadful, the output of one of their side projects has been very important for the rest of us. Helpful PowerShell cmdlets! One hundred seventy-three to be exact. Still not the 800+ we have with on-prem, but still pretty awesome.

One of the best things they have done is embrace some of the shortcomings of on-prem with cmdlets like:

  • Add-SPOFile & Add-SPOListItem ? For all of your list population needs
  • New-SPOList & GetSPOList ? About time
  • Get-SPOHealthScore ? No more reading web headers
  • And a lot more.

Honestly, every goofy thing I have wanted to do so far there has used a cmdlet to do it instead of with on-prem, where I have to go into objects and manipulate their methods and properties manually. Pretty cool. Unfortunately, they have had to do that to make up for the fact that you cannot edit SPO objects and then run the Update() method like we do on-prem. So you win some, you lose some. Still, what the PNP team has created is awesome.

Installing the PNP PowerShell cmdlets
As a side note, if you hate reading my directions, you may enjoying watching them more. I have a video for Installing the Patterns and Practices PowerShell for SharePoint Online that has a lot more detail.

Time to cut to the chase and show you how to get them installed. Before I do, though, three quick reminders:

  1. You need to be a local administrator to run PowerShell as an administrator.
  2. You need your execution policy to allow the remote scripts to run. -RemoteSigned is probably the option that you should be using.
  3. You need the appropriate permissions in SharePoint Online. PowerShell isn't your way around your company's security.

With that said, you can now install the cmdlets.

  1. Open PowerShell as an administrator.
  2. Type Install-Module SharePointPnPPowerShellOnline -AllowClobber

At a minimum you will get a security warning about trusting the remote gallery. (Yes, you do.) You may also get prompted to install NuGet if this is your first time installing a module from the Internet. Either way, power through those messages with the letter Y and you will have PNP PowerShell. Also, if you are wondering why do you have to use -AllowClobber, that is because the SPO cmdlets that Microsoft gave you have some overlap. Get-SPOSite for example is in both packages, so you have to clobber one to get the other.

Connecting to your SPO site
I figured it would be rude not to give you some pointers to get started, so here they are.

  1. Put your Username and Password in a variable. Doing so will save you typing later.
    1. $credential = get-credential
  2. Connect to your SPO site by typing in the following changing the URL to be the URL of your site collection. Keep in mind that you will need to run this each time you want to switch to a different site collection in your tenant.
    1. Connect-SPOnline -URL https://<yourtenant>.sharepoint.com -Credential $credential
  3. Now confirm it all worked by running something simple.
    1. Get-SPOWeb.
    2. If you get something back, then you are up and running.
  4. The last thing is to run the following to see a list of all of the cmdlets you now have.
    1. Get-Command -Module Microsoft.Online.Sharepoint.PowerShell

You now have all of the tools you need to become a whiz with the PNP PowerShell for SPO. Enjoy!

Shane Young is a SharePoint MVP and member of Bold Zebras.

View all Blog Posts