Tuesday, November 11, 2025

POWERSHELL COMMANDS ON SHAREPOINT ONLINE SITES

 POWERSHELL COMMANDS ON SHAREPOINT ONLINE SITES

PowerShell commands for SharePoint Online (SPO) greatly simplify administration tasks such as site management, permissions handling, and reporting. The SharePoint Online Management Shell provides a collection of cmdlets (commands) starting with "SPO" or "PnP" (for PnP PowerShell) that administrators use to automate and streamline management.

Commonly Used PowerShell Commands on SharePoint Online Sites

  1. Connect to SharePoint Online Admin Center

    powershell
    Connect-SPOService -Url https://<tenant>-admin.sharepoint.com

    Establishes a session with the SharePoint Online admin center.

  2. Get List of Site Collections

    powershell
    Get-SPOSite

    Retrieves all SharePoint Online site collections in your tenant.

  3. Get Detailed Site Information

    powershell
    Get-SPOSite -Identity https://contoso.sharepoint.com/sites/siteName -Detailed

    Provides detailed properties of a specific site.

  4. Create a New Site Collection

    powershell
    New-SPOSite -Url https://contoso.sharepoint.com/sites/newsite -Owner user@contoso.com -StorageQuota 1024 -Template STS#0 -Title "New Site"

    Creates a new site with specified owner, storage quota, template, and title.

  5. Update Site Collection Properties

    powershell
    Set-SPOSite -Identity https://contoso.sharepoint.com/sites/siteName -StorageQuota 2048 -Title "Updated Title"

    Modifies settings like storage quota and title for an existing site.

  6. Remove a Site Collection

    powershell
    Remove-SPOSite -Identity https://contoso.sharepoint.com/sites/oldsite

    Deletes a specified site collection.

  7. Manage Site Collection User Permissions

    • Add user to site owners group:

      powershell
      Add-SPOUser -Site https://contoso.sharepoint.com/sites/siteName -LoginName user@contoso.com -Group "Site Owners"
    • Remove user from a group:

      powershell
      Remove-SPOUser -Site https://contoso.sharepoint.com/sites/siteName -LoginName user@contoso.com -Group "Site Members"
  8. Get Site Collection Storage Usage

    powershell
    Get-SPOSite | Select URL, StorageUsageCurrent | Format-Table

    Lists site URLs and their current storage usage.

  9. Restore a Deleted Site

    powershell
    Restore-SPODeletedSite -Identity https://contoso.sharepoint.com/sites/deletedsite
  10. Using PnP PowerShell for More Granular Tasks

    • Connect to site:

      powershell
      Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/siteName -Interactive
    • Get all lists:

      powershell
      Get-PnPList
    • Add user to SharePoint group:

      powershell
      Add-PnPGroupMember -Identity "Site Members" -LoginName user@contoso.com