Thursday, March 30, 2023

SharePoint Online PowerShell

Installing SharePoint Online Management Shell

To connect to SharePoint Online, you need to install SharePoint Online Management Shell. This PowerShell module allows you to manage SharePoint Online subscription in the Office 365. To install this module, PowerShell 3.0 (included in Windows Management Framework 3.0) must be installed on your computer. Download SharePoint Online Management Shell here.


Get-Command –Module Microsoft.Online.SharePoint.PowerShell (A complete list of available commands of the module Microsoft.Online.SharePoint.PowerShell.dll can be displayed in the way like this)


Install-Module Microsoft.Online.SharePoint.PowerShell

Get-Command *-SPO*

The most frequently used cmdlets are listed below:

  • Add-SPOUser
  • Connect-SPOService
  • Disconnect-SPOService
  • Get-SPOExternalUser
  • Get-SPOSite
  • Get-SPOSiteGroup
  • Get-SPOTenant
  • Get-SPOUser
  • New-SPOSite
  • New-SPOSiteGroup
  • Remove-SPOSite
  • Remove-SPOSiteGroup
  • Remove-SPOUser
  • Set-SPOUser
  • Set-SPOUser
  • Test-SPOSite
  • Upgrade-SPOSite

Depending on your OS, you need to download 32 or 64 bit MSI distribution.

Connect to SharePoint Online

1. Connect-SPOService –Url https://contoso-admin.sharepoint.com


Get All SharePoint Online Site Collections

Get-SPOSite

Get-SPOSite –identity <SiteURL> | Select *

 

View All Users in the Site Collection


Get-SPOUser –Site <SiteURL>

Get-SPOUser -Site <SiteURL> | where {$_.isGroup -ne $false}

Find All External Users in SharePoint Online 


Get-SPOExternalUser –PageSize 50

Get-SPOExternalUser -Position 0 -PageSize 30 -SiteUrl https://contoso.sharepoint.com

List Deleted Sites Using PowerShell


Get-SPODeletedSite (The Get-SPODeletedSite cmdlet returns all the deleted site collections from the recycle bin. )

Get-SPODeletedSite –IncludePersonalSite (The result includes site URL, deletion time, days remaining to restore the site, etc. You can use an audit log search to find out who deleted the site collection.)


If you want to restore the deleted SharePoint site, you can use the Restore-SPODeletedSite as shown below.

Restore-SPODeletedSite –Identity <SiteURL>


Get-SPFarm | Select BuildVersion ( You can check the version of SharePoint)


Get-SPOSite (To list all site collection.)

Get-SPSite | Get-Member

Set-SPOUser -Site {Corporate Blog} -LoginName root@theitbros.com -IsSiteCollectionAdmin $true -- Add new Site Collection administrator

Remove-SPOUser -LoginName root@theitbros.com -Site {Corporate Blog} -- To remove a user from the Site Collection Administrator group

Get-SPWebTemplate -- Available templates can be viewed with the command

Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "SITE"} -- List of installed components


Get-SPWebTemplate | where {$_.Title -match "business"} -- List of available site templates

Get-Service | Where-Object {$_.DisplayName -like "Sharep*"} -- List of running SharePoint services

Test-SPContentDatabase -name WSS_Content –webapplication http://abc.com -- Check the content database for errors


Get SharePoint Online Tenant Settings

Get-SPOTenant (
By using the Get-SPOTenant cmdlet, you can view organization-level site collection properties. )



Find SharePoint Sites Linked with Private Channels

Get-SPOSite -Template "TEAMCHANNEL#0" (When a private channel is created in Microsoft Teams, it creates a SharePoint site automatically. To identify SharePoint sites created as a result of private channels, run the following cmdlet.)

The template value “TEAMCHANNEL#0” denotes the site collection provisioned for each Teams private channel. 

We have listed few SharePoint Online template IDs below: 

STS#0 – Shows classic Teams sites 

STS#3 – Lists Teams sites that has no connection to the Office 365 group 

Group#0 – Retrieves Office 365 group associated Teams sites 

Note: When a team is created, a Microsoft 365 group is generated. Each Microsoft 365 group creates a SharePoint site to store the shared documents. You can download our dedicated script to identify Teams and their SharePoint site URL. 


Challenges in Managing SharePoint Online with PowerShell

SharePoint Online integrates multiple Office 365 components like Microsoft 365 groups, Teams, Private Channels, One Drive for Business, etc. So, the SharePoint Online PowerShell module alone is insufficient to generate all the SPO reports. 

  • It requires juggling multiple Office 365 PowerShell modules. 
  • For auditing SharePoint Online, you need to create an Exchange Online PowerShell session to use the Search-UnifiedAuditLog cmdlet.  
  • Sending a report by email is one of the tedious tasks. 




No comments:

Post a Comment