Skip to content
All articlesSharePoint

How to use SharePoint Powershell

Learn how to use PowerShell to manage SharePoint Online with essential commands, automate tasks, and secure permissions. Ideal for SharePoint administrators

6 June 2024Updated8 Oct 20249 min read
How to use SharePoint Powershell

PowerShell Power Up: Mastering SharePoint Online Management Shell

The PowerShell SharePoint Online Management Shell (SPO Management Shell) is an indispensable tool for administrators seeking to harness the full potential of SharePoint Online. Unlike the standard user interface, the PowerShell SPO Management Shell offers advanced users granular control over their SharePoint environments. Whether you’re managing a complex network of sites or automating routine tasks, PowerShell within the SPO Management Shell provides the flexibility and power to streamline your operations efficiently.

The primary benefit of using the SPO Management Shell lies in its ability to execute complex tasks with precision and efficiency. Advanced users, in particular, can leverage its capabilities to automate repetitive processes, enforce security policies consistently, and manage large-scale deployments with ease. This level of control can significantly enhance productivity and ensure that your SharePoint Online environment runs smoothly and securely.

TopicKey Points
IntroductionSPO Management Shell offers granular control and automation capabilities for SharePoint Online.
Getting StartedDetailed steps to install and connect to the SPO Management Shell.
Basic Navigation CommandsExamples of commands to navigate and manage SharePoint Online sites and lists.
Common Use CasesPractical examples of creating sites, managing permissions, and automating tasks with PowerShell.
Learning ResourcesOfficial documentation, online communities, training courses, and blogs for further learning.
ConclusionEmphasizes the power and flexibility of the SPO Management Shell and encourages further exploration.
## Getting Started with SharePoint Powershell To begin your journey with the [SharePoint](/sharepoint-online-faqs/) Online Management Shell, you’ll first need to install and connect it to your SharePoint Online environment. Here’s a step-by-step guide to get you started: ### Step 1: Install the SharePoint Online Management Shell 1. **Download the SharePoint Online Management Shell:** Visit the [Microsoft Download Center](https://www.microsoft.com/en-us/download/details.aspx?id=35588) and download the latest version of the SPO Management Shell. 2. **Run the Installer:** Execute the downloaded file and follow the on-screen instructions to install the SPO Management Shell on your computer. 3. **Verify the Installation:** Open PowerShell and run the following command to ensure the SPO Management Shell is installed correctly: _Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell_ ## Mastering SharePoint Online Please fill out the form below to get our free Ebook "Mastering SharePoint Online" emailed to you FREE DOWNLOAD Send download link to: ### Step 2: Connect to SharePoint Online 1. **Open the SharePoint Online Management Shell:** Launch the SPO Management Shell from your Start menu or by running `powershell` and importing the module manually. 2. **Connect to Your SharePoint Online Admin Center:** Use the following command to connect to your SharePoint Online Admin Center: _Connect-SPOService -Url [https://](https://\)_ 3. Replace `` with the URL of your SharePoint Online Admin Center (e.g., `https://contoso-admin.sharepoint.com`). 4. _**Authenticate:** When prompted, enter your SharePoint Online admin credentials._ ### Step 3: Basic Commands for Navigating SharePoint Online Once connected, you can start using basic commands to navigate and manage your SharePoint Online environment. Here are a few essential commands to get you started: - **Get a list of all site collections: **_Get-SPOSite_ - **Retrieve details of a specific site collection: **_Get-SPOSite -Identity [https://contoso.sharepoint.com/sites/HR](https://contoso.sharepoint.com/sites/HR)_ - **List all SharePoint Online users: **_Get-SPOUser -Site [https://contoso.sharepoint.com/sites/HR](https://contoso.sharepoint.com/sites/HR)_ These commands provide a solid foundation for navigating your [SharePoint Online](/mastering-sharepoint-online/) environment. As you become more comfortable with the SPO Management Shell, you can start exploring more advanced commands and scripts to automate tasks and streamline your workflows. ## SharePoint Storage Explorer Gain insights in to your SharePoint Online Storage Consumption Download our completely FREE TOOL FREE DOWNLOAD Send download link to: ## Common Use Cases The true power of the SharePoint Online Management Shell shines when you start using it to perform common administrative tasks. Here are a few practical examples with code snippets: ### Create and Manage SharePoint Sites and Lists Creating and managing sites and lists is a frequent task for SharePoint administrators. With the SPO Management Shell, you can easily create new site collections and lists: - **Create a new site collection: **_New-SPOSite -Url https://contoso.sharepoint.com/sites/NewSite -Owner -StorageQuota 1000 -Title “New Site Collection”_ - **Create a new list within a site:** _Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/NewSite -UseWebLogin_ _New-PnPList -Title “New List” -Template GenericList_ ### Set User Permissions and Security Settings Managing user permissions is crucial for maintaining the security and integrity of your SharePoint Online environment. With the SPO Management Shell, you can efficiently manage user access: - **Add a user to a site collection: **_Add-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginName -Role “Site Owner”_ - **Remove a user from a site collection:** _Remove-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginName_ ### Automate Tasks with Scripting Automation is one of the most powerful features of the SPO Management Shell. By scripting common tasks, you can save time and reduce the potential for errors: - **Bulk user provisioning: **_$users = Import-Csv -Path “C:\\Users\\NewUsers.csv”** foreach ($user in $users) { Add-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginName $user.Email -Role “Member” \}**_ ## SharePoint Storage Explorer Gain insights in to your SharePoint Online Storage Consumption Download our completely FREE TOOL FREE DOWNLOAD Send download link to: ## Learning Resources To master the SharePoint Online Management Shell, it’s essential to tap into a variety of learning resources. These resources can provide you with the latest updates, best practices, and troubleshooting tips to enhance your knowledge and efficiency. ### Official Microsoft Documentation The first stop for any SharePoint Online Management Shell user should be the official Microsoft documentation. This comprehensive resource offers detailed explanations, syntax for commands, and examples to help you get the most out of the SPO Management Shell. - **SharePoint Online Management Shell Documentation:** Visit the [official Microsoft documentation](https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?view=sharepoint-ps) for detailed information on connecting to and using the SharePoint Online Management Shell. This resource is regularly updated with new features and best practices. ### Online Communities and Forums Engaging with online communities can provide invaluable insights and support from fellow SharePoint administrators and PowerShell enthusiasts. These communities are great places to ask questions, share experiences, and learn from others’ challenges and solutions. - **Microsoft Tech Community:** The [Microsoft Tech Community](https://techcommunity.microsoft.com/t5/sharepoint/ct-p/SharePoint) is a vibrant forum where you can discuss SharePoint Online and PowerShell topics. It’s a great place to find answers to specific questions and to stay updated on the latest developments. - **Reddit SharePoint Community:** The [Reddit SharePoint Community](https://www.reddit.com/r/sharepoint/) is another excellent resource for troubleshooting and discussion. With a wide range of topics and active participants, you can gain diverse perspectives on managing SharePoint Online with PowerShell. ### Training Courses and Tutorials Structured training courses and video tutorials can offer step-by-step guidance and hands-on experience with the SharePoint Online Management Shell. These resources are particularly useful for visual learners and those who prefer a more guided learning experience. - **Pluralsight:** Pluralsight offers comprehensive courses on SharePoint Online and PowerShell. These courses cover everything from basic commands to advanced scripting techniques, helping you build a solid foundation. - **YouTube Tutorials:** Numerous YouTube channels provide free tutorials on SharePoint Online and PowerShell. Channels like [SharePoint Maven](https://www.youtube.com/channel/UCUxC8g4edfgVlfa4ARsUD0g) offer practical tips and demonstrations that can help you understand and apply various commands. ## Conclusion The SharePoint Online Management Shell is a powerful tool that offers unmatched flexibility and control for managing your SharePoint Online environment. By leveraging the resources mentioned above, you can deepen your understanding, enhance your skills, and unlock the full potential of the SPO Management Shell.

Whether you’re looking to automate routine tasks, enforce security policies, or manage complex deployments, the SharePoint Online Management Shell provides the tools you need to succeed. Embrace the power and flexibility it offers, and continue exploring its capabilities to become a SharePoint Online PowerShell expert.

SharePoint PowerShell Commands

CommandDescription
Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShellVerify the installation of the SPO Management Shell.
Connect-SPOService -Url https://<your-admin-center-url>Connect to the SharePoint Online Admin Center.
Get-SPOSiteGet a list of all site collections.
Get-SPOSite -Identity https://contoso.sharepoint.com/sites/HRRetrieve details of a specific site collection.
Get-SPOUser -Site https://contoso.sharepoint.com/sites/HRList all SharePoint Online users within a specific site.
New-SPOSite -Url https://contoso.sharepoint.com/sites/NewSite -Owner -StorageQuota 1000 -Title "New Site Collection"Create a new site collection.
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/NewSite -UseWebLoginConnect to a specific SharePoint Online site using PnP PowerShell.
New-PnPList -Title "New List" -Template GenericListCreate a new list within a site using PnP PowerShell.
Add-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginName -Role "Site Owner"Add a user to a site collection.
Remove-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginNameRemove a user from a site collection.
powershell<br>$users = Import-Csv -Path "C:\Users\NewUsers.csv"<br>foreach ($user in $users) \{<br>Add-SPOUser -Site https://contoso.sharepoint.com/sites/NewSite -LoginName $user.Email -Role "Member"<br>\}Script to bulk provision users from a CSV

Squirrel: Effortless SharePoint Archiving

Streamline your SharePoint archiving with Squirrel! Automate document archiving to Azure Blob Storage and ensure easy access and security. Make SharePoint management simple and efficient with Squirrel.

Squirrel for SharePoint Site Size Reporting

Save costs with Squirrel. Automate SharePoint archiving to Azure Blob Storage, reducing expenses while ensuring secure and accessible data. Efficient and budget-friendly.

Ready To Reduce SharePoint Online Costs?

Book a Squirrel Demo Today

Frequently Asked Questions About SharePoint PowerShell

What PowerShell module do I need for SharePoint Online? The SharePoint Online Management Shell module, installed via Install-Module -Name Microsoft.Online.SharePoint.PowerShell. PnP PowerShell (Install-Module PnP.PowerShell) is the modern alternative with broader functionality and is increasingly the recommended tool for automation.

How do I connect to SharePoint Online with PowerShell? With the official module, run Connect-SPOService and supply the tenant admin URL. With PnP PowerShell, run Connect-PnPOnline against a specific site URL with the -Interactive flag. Both prompt for authentication; service principal or certificate auth is supported for unattended automation.

What can I do with SharePoint PowerShell that I cannot do in the admin centre? Bulk operations across many sites at once, custom audit and reporting, automated provisioning of sites and permissions, scripted retention and disposition workflows, and integration with external systems via Microsoft Graph. The admin centre handles individual changes; PowerShell handles scale.

How do I list all SharePoint sites with PowerShell? Run Get-SPOSite -Limit All to return every site in the tenant. Add -Detailed to include storage usage and quotas. The PnP equivalent is Get-PnPTenantSite. Both can be piped to Export-Csv for reporting.

Can I use PowerShell to archive SharePoint documents? PowerShell can move documents between libraries, but moving them to cheaper storage outside SharePoint (the actual archiving use case) typically requires a purpose-built tool. Squirrel automates that workflow without custom PowerShell.

What permissions do I need to run SharePoint PowerShell? SharePoint admin or Global admin in Microsoft 365 for tenant-level commands. For site-level commands, Site Collection Administrator on the target site. For unattended automation, register an Entra ID app with the appropriate Microsoft Graph and SharePoint permissions, granted by an admin.

Ready when you are

Cut your Microsoft 365 storage bill - keep your data in your tenant.