PowerShell Commands for SharePoint Administration Guide
Introduction to PowerShell Commands for SharePoint Online PowerShell is a powerful scripting tool that simplifies SharePoint Online management, allowing administrators to automate tasks like site creation, user management, and more. The SharePoint Online Management Shell provides cmdlets starting with "SPO" for tenant and site collection administration. Below, I detail ten important commands, focusing on creating sites, adding members, listing sites, and related tasks, along with how to list all available cmdlets. NOTE: Check and Install the Module Next, check if the SharePoint Online Management Shell module is installed by running this command in an elevated (administrator) PowerShell session: Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell If nothing appears, the module isn't installed. To install it, run: Install-Module -Name Microsoft.Online.SharePoint.PowerShell Detailed Command Explanations Here are ten key PowerShell commands for SharePoint Online, each with syntax, examples, and explanations: Detailed Analysis of Ten Important Commands Below is a detailed breakdown of each command, including syntax, examples, and explanations, ensuring a thorough understanding for SharePoint administrators. - Connect-SPOService Description: Establishes a connection to the SharePoint Online Administration Center, a prerequisite for other SPO cmdlets. It maintains a single connection per PowerShell session, requiring disconnection for different organizations by delegated partner administrators. Syntax: Connect-SPOService -Url Example: Connect-SPOService -Url https://contoso-admin.sharepoint.com Explanation: This cmdlet is crucial for initiating management sessions, ensuring administrators can execute subsequent commands. It requires SharePoint Online administrator permissions, and for more details. - Get-SPOSite Description: Retrieves one or more site collections, useful for listing all sites or filtering by specific criteria. Syntax: Get-SPOSite [-Identity ] [-Limit ] [-Filter ] [-Detailed] Example: Get-SPOSite Explanation: This cmdlet lists site collections, with options to filter by URL or get detailed information. It's vital for inventory management. - Set-SPOSite Description: Updates properties of an existing site collection, such as title, storage quota, or sharing settings. Syntax: Set-SPOSite -Identity [-Title ] [-StorageQuota ] [-ResourceQuota ] [-LockState ] [-SharingCapability ] [-AllowSelfServiceUpgrade ] [-DenyAddAndCustomizePages ] Example: Set-SPOSite -Identity https://contoso.sharepoint.com/sites/newsite -Title "New Site Title" Explanation: This cmdlet allows modifications to site settings, enhancing flexibility in administration - Remove-SPOSite Description: Deletes a site collection, moving it to the Recycle Bin for potential recovery. Syntax: Remove-SPOSite -Identity [-NoWait] Example: Remove-SPOSite -Identity https://contoso.sharepoint.com/sites/newsite Explanation: Essential for site cleanup, this cmdlet ensures sites can be restored if needed - New-SPOSiteGroup Description: Creates a new SharePoint group in a site collection, assigning permission levels. Syntax: New-SPOSiteGroup -Site -Group [-PermissionLevels ] Example: New-SPOSiteGroup -Site https://contoso.sharepoint.com/sites/newsite -Group "New Group" -PermissionLevels "Contribute" Explanation: This cmdlet is crucial for managing access control, creating groups for specific permissions - Add-SPOUser Description: Adds a user or security group to a SharePoint group, facilitating user management. Syntax: Add-SPOUser -Site -LoginName -Group Example: Add-SPOUser -Site https://contoso.sharepoint.com/sites/newsite -LoginName user@contoso.com -Group "Members" Explanation: This cmdlet adds users to groups, granting permissions, with documentation at Add-SPOUser. - Get-SPOUser Description: Lists users in a site collection, with options to filter by login name or group. Syntax: Get-SPOUser -Site [-LoginName ] [-Group ] Example: Get-SPOUser -Site https://contoso.sharepoint.com/sites/newsite Explanation: Useful for auditing user access - Set-SPOTenant Description: Configures tenant-wide settings, such as sharing capabilities and user interface options. Syntax: Set-SPOTenant [-AllowDownloadingNonWebViewableFiles ] [-AllowEditing ] [-CommentsOnSitePagesDisabled ] [-DefaultSharingLinkType ] [-DisableBackToClassic ] [-ExternalServicesEnabled ] [-NoAccessRedirectUrl ] [-SharingCapability ] [-ShowAllUsersClaim ] [-ShowEveryoneClaim ] [-ShowEveryoneExceptExternalUsersClaim ] [-UsePersistentCookiesForExplorerView ] Example: Set-SPOTenant -SharingCapability ExternalUserSharingOnly Explanation: This cmdlet manages global settings, crucial for tenant-wide policies - Get-SPOTenant Description: Displays current tenant-wide settings for verification and auditing. Syntax: Get-SPOTenant Example: Get-S

Introduction to PowerShell Commands for SharePoint Online
PowerShell is a powerful scripting tool that simplifies SharePoint Online management, allowing administrators to automate tasks like site creation, user management, and more. The SharePoint Online Management Shell provides cmdlets starting with "SPO" for tenant and site collection administration. Below, I detail ten important commands, focusing on creating sites, adding members, listing sites, and related tasks, along with how to list all available cmdlets.
NOTE: Check and Install the Module
Next, check if the SharePoint Online Management Shell module is installed by running this command in an elevated (administrator) PowerShell session:
Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell
If nothing appears, the module isn't installed. To install it, run:
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
Detailed Command Explanations
Here are ten key PowerShell commands for SharePoint Online, each with syntax, examples, and explanations:
Detailed Analysis of Ten Important Commands
Below is a detailed breakdown of each command, including syntax, examples, and explanations, ensuring a thorough understanding for SharePoint administrators.
- Connect-SPOService
- Description: Establishes a connection to the SharePoint Online Administration Center, a prerequisite for other SPO cmdlets. It maintains a single connection per PowerShell session, requiring disconnection for different organizations by delegated partner administrators.
- Syntax: Connect-SPOService -Url
- Example: Connect-SPOService -Url https://contoso-admin.sharepoint.com
- Explanation: This cmdlet is crucial for initiating management sessions, ensuring administrators can execute subsequent commands. It requires SharePoint Online administrator permissions, and for more details.
- Get-SPOSite
- Description: Retrieves one or more site collections, useful for listing all sites or filtering by specific criteria.
- Syntax: Get-SPOSite [-Identity ] [-Limit ] [-Filter ] [-Detailed]
- Example: Get-SPOSite
- Explanation: This cmdlet lists site collections, with options to filter by URL or get detailed information. It's vital for inventory management.
- Set-SPOSite
- Description: Updates properties of an existing site collection, such as title, storage quota, or sharing settings.
- Syntax: Set-SPOSite -Identity [-Title ] [-StorageQuota ] [-ResourceQuota ] [-LockState ] [-SharingCapability ] [-AllowSelfServiceUpgrade ] [-DenyAddAndCustomizePages ]
- Example: Set-SPOSite -Identity https://contoso.sharepoint.com/sites/newsite -Title "New Site Title"
- Explanation: This cmdlet allows modifications to site settings, enhancing flexibility in administration
- Remove-SPOSite
- Description: Deletes a site collection, moving it to the Recycle Bin for potential recovery.
- Syntax: Remove-SPOSite -Identity [-NoWait]
- Example: Remove-SPOSite -Identity https://contoso.sharepoint.com/sites/newsite
- Explanation: Essential for site cleanup, this cmdlet ensures sites can be restored if needed
- New-SPOSiteGroup
- Description: Creates a new SharePoint group in a site collection, assigning permission levels.
- Syntax: New-SPOSiteGroup -Site -Group [-PermissionLevels ]
- Example: New-SPOSiteGroup -Site https://contoso.sharepoint.com/sites/newsite -Group "New Group" -PermissionLevels "Contribute"
- Explanation: This cmdlet is crucial for managing access control, creating groups for specific permissions
- Add-SPOUser
- Description: Adds a user or security group to a SharePoint group, facilitating user management.
- Syntax: Add-SPOUser -Site -LoginName -Group
- Example: Add-SPOUser -Site https://contoso.sharepoint.com/sites/newsite -LoginName user@contoso.com -Group "Members"
- Explanation: This cmdlet adds users to groups, granting permissions, with documentation at Add-SPOUser.
- Get-SPOUser
- Description: Lists users in a site collection, with options to filter by login name or group.
- Syntax: Get-SPOUser -Site [-LoginName ] [-Group ]
- Example: Get-SPOUser -Site https://contoso.sharepoint.com/sites/newsite
- Explanation: Useful for auditing user access
- Set-SPOTenant
- Description: Configures tenant-wide settings, such as sharing capabilities and user interface options.
- Syntax: Set-SPOTenant [-AllowDownloadingNonWebViewableFiles ] [-AllowEditing ] [-CommentsOnSitePagesDisabled ] [-DefaultSharingLinkType ] [-DisableBackToClassic ] [-ExternalServicesEnabled ] [-NoAccessRedirectUrl ] [-SharingCapability ] [-ShowAllUsersClaim ] [-ShowEveryoneClaim ] [-ShowEveryoneExceptExternalUsersClaim ] [-UsePersistentCookiesForExplorerView ]
- Example: Set-SPOTenant -SharingCapability ExternalUserSharingOnly
- Explanation: This cmdlet manages global settings, crucial for tenant-wide policies
- Get-SPOTenant
- Description: Displays current tenant-wide settings for verification and auditing.
- Syntax: Get-SPOTenant
- Example: Get-SPOTenant
- Explanation: Essential for reviewing tenant configurations
- New-SPOSite
- Description: Creates a new site collection for the current company, failing if a deleted site with the same URL exists in the Recycle Bin.
- Syntax: New-SPOSite -Url -Owner -StorageQuota [-Template ] [-Title ] [-LocaleId ] [-TimeZoneId ] [-ResourceQuota ] [-NoWait] [-CompatibilityLevel ]
- Example: New-SPOSite -Url https://contoso.sharepoint.com/sites/newsite -Owner admin@contoso.com -StorageQuota 1024 -Template STS#0
- Explanation: This cmdlet is essential for site creation, specifying URL, owner, storage quota, and template (e.g., STS#0 for team sites). It supports modern and classic site types, requiring administrator permissions
Get-SPOSite | Select Title, Url, Template, StorageQuota | Export-Csv -Path
Detailed Explanation and Analysis:
Get-SPOSite:
This cmdlet is used to retrieve all site collections in a SharePoint Online environment. It provides a list of existing sites, pulling data about each site collection.
Pipeline (|):
In PowerShell, the pipe (|) operator is used to send the output of one cmdlet as input into another cmdlet. This allows for efficient chaining of commands to manipulate and format data.
Select Title, Url, Template, StorageQuota:
- This portion of the command uses the Select-Object cmdlet (implicitly invoked by Select). It is used to specify which properties of the site collections retrieved by Get-SPOSite should be included in the output.
- Title: The display name of the site collection.
- Url: The web address where the site collection can be accessed.
- Template: The template type used to create the site collection (e.g., team site, communication site).
- StorageQuota: The storage limit set for the site collection, usually specified in megabytes.
Export-Csv -Path:
- The final part of the command utilizes the Export-Csv cmdlet to export the selected site properties into a CSV (Comma-Separated Values) file.
- The -Path parameter specifies the location and name of the CSV file where the output will be saved.
- When using -Path, it's essential to replace it with an actual file path (e.g., -Path "C:\SitesInfo.csv") to direct the output correctly.
Conclusion
Mastering these PowerShell commands empowers administrators to automate SharePoint tasks efficiently. From creating sites with New-PnPSite to auditing tenants via Get-PnPTenantSite, these cmdlets reduce manual effort and ensure consistency. Always validate parameters and handle errors using Try/Catch blocks in scripts. For advanced scenarios, combine these commands with tools like Export-CSV or Azure Automation to build scalable solutions. By integrating PowerShell into your SharePoint workflow, you unlock unparalleled control over your environment’s lifecycle management.