Follow Us:
If you've spent any time administrating SharePoint, you've inevitably become frustrated with managing access, settings, and other items manually. Wouldn't it be great if there was a magic spell that would complete tasks quicker?
That magic spell comes in the form of PowerShell! SharePoint Online Management Shell (a PowerShell module) provides an easy way to complete bulk tasks, change settings quickly, and perform actions not otherwise available.
If you're new to PowerShell it may sound complicated and the image below might look like a foreign language.
Don't worry—I'm giving a simple, step-by-step process you can follow to make your magic happen in SharePoint!
The SharePoint Online Management Shell is a Windows PowerShell module. Essentially, we'll be using a PowerShell module specifically for SharePoint. Check out this article from Microsoft to learn more about PowerShell.
PowerShell works through "cmdlets" or PowerShell commands. Cmdlets are lines of scripts written in a specific syntax that you can input into the module to change/add/update things on applications.
The main difference between cmdlets in Windows PowerShell and the SharePoint Online Management Shell is the nouns used. Windows PowerShell starts with MSO, while SharePoint Online starts with SPO.
Simple cmdlets are easy to use even for beginners. Microsoft provides excellent documentation for many commands that users need to only tweak before running.
In many cases, you'll mostly copy/paste with no need to learn the syntax or write scripts from scratch. I'll show you what I mean.
To use SharePoint Online PowerShell commands, you need the SharePoint Administrator or Global Administrator role in Microsoft 365.
Every Windows computer comes equipped with the Windows PowerShell app by default, but you'll need to install the SharePoint Online Management shell module.
Select the orange "Download" button on this page and install the application by opening the setup wizard and walking through the onscreen prompts.
Once the installation is complete, you're ready to run your first command!
The first step is logging in to SharePoint Online via a simple cmdlet.
Use the sample cmdlet provided below. You'll need to replace the yellow highlighted section with the URL of your tenant's SharePoint Online admin center.
Connect-SPOService -Url https://DemoTenant-admin.sharepoint.com
Follow these steps to connect:
A pop-up will appear asking for your login information. Once you log in, you're connected! You'll need to repeat these steps each time you open the SharePoint Online Management Shell module.
Now that you're connected let's get started doing some magic.
Some cmdlets allow you to display the information you're looking for quickly. Others will get lists of sites, groups, and users.
1. Get a list of the sites in your tenant with this command:
Get-SPOSite
2. Get a list of the groups in your tenant with this command:
Get-SPOSite | ForEach {Get-SPOSiteGroup -Site $_.Url} | Format-Table
Note: This series of commands demonstrates a unique capability in PowerShell known as "piping." Each command is fed inputs from the previous command.
3. Get a list of the users in your tenant with this command:
Get-SPOSite | ForEach {Get-SPOUser -Site $_.Url}
4. Get all users and security groups for a specific SharePoint site.
Get-SPOUser –Site <Site URL>
Tip: Remember that to run a command, you must paste the cmdlet into the window and press the "Enter" key on your keyboard.
There are a variety of cmdlets for streamlining your process of adding users and groups to a site.
1. Use the Add-SPOUser cmdlet to add users to a group.
Add-SPOUser -Site <Site URL> -LoginName <User Email> -Group <Group Name>
The easiest way to add a large list of groups to sites is to prepare a CSV file and then utilize a PowerShell command.
1. Create a CSV file with headers/columns corresponding to the parameters defined in the PowerShell script. In this case, we're adding groups to sites, so we'll need to define Group, Site, and Permission Levels.
The CSV should have those three column headers with the corresponding data below. Make sure you format your data as a table with headers. See the sample below.
2. Use the Import-Csv command as shown below, replacing the highlighted section with the file path for the CSV.
Import-Csv C:\Users\JohnSmith\Downloads\Groups.csv | ForEach {New-SPOSiteGroup -Group $_.Group -PermissionLevels $_.PermissionLevels -Site $_.Site}
Similarly, you can add one or more users to one or more groups.
1. Create a CSV file with headers/columns corresponding to the parameters defined in the PowerShell script. In this case, we're adding users to groups, so we'll need to define Group, LoginName, and Site.
(Note: There's no need for Permission Levels since the group will already have permissions applied).
The CSV should have those three column headers with the corresponding data below. Make sure you format your data as a table with headers.
Import-Csv C:\Users\JohnSmith\Downloads\Users.csv | ForEach {Add-SPOUser -Group $_.Group –LoginName $_.LoginName -Site $_.Site}
This only brushes the surface of what can be done quickly through simple PowerShell cmdlets. Check out Microsoft's Cmdlet reference to get started with simple cmdlets for frequently performed tasks in SharePoint.
Looking for additional tutorials? Read more from the C5 Insight blog!
The complementary paper includes over 12 years of research, recent survey results, and CRM turnaround success stories.
Request Download
This 60-second assessment is designed to evaluate your organization's collaboration readiness.
Learn how you rank compared to organizations typically in years 1 to 5 of implementation - and which areas to focus on to improve.
This is a sandbox solution which can be activated per site collection to allow you to easily collect feedback from users into a custom Feedback list.
Whether you are upgrading to SharePoint Online, 2010, 2013 or the latest 2016, this checklist contains everything you need to know for a successful transition.