Monday, May 25, 2026

Daily - SharePoint Online PowerShell Tasks

 Daily - SharePoint Online PowerShell Tasks

SharePoint Online PowerShell Tasks with Real-Time Examples

For SharePoint Online administration, the most commonly used modules are:

  1. SharePoint Online Management Shell
  2. PnP PowerShell (Recommended by Microsoft)
  3. Microsoft Graph PowerShell (for advanced M365 administration)

 

1. Connect to SharePoint Online Admin Center

Task

Connect to the SharePoint Online tenant.

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

Verify Connection

Get-SPOTenant

Real-Time Use

Daily administration tasks require connecting to the tenant before executing commands.

 

2. List All SharePoint Sites

Task

Retrieve all site collections.

Get-SPOSite

Large Environment

Get-SPOSite -Limit All

Output

HR Site
Finance Site
IT Site
Projects Site

Real-Time Use

Site inventory and governance audits.

 

3. Create a New Site Collection

Task

New-SPOSite `
-Url https://contoso.sharepoint.com/sites/HR `
-Owner admin@contoso.com `
-StorageQuota 1024 `
-Title "HR Portal"

Real-Time Use

Creating department sites.

 

4. Get Site Storage Usage

Get-SPOSite | Select URL, StorageUsageCurrent

Real-Time Use

Monitor storage consumption.

 

5. Find Sites Larger Than 50 GB

Get-SPOSite -Limit All |
Where-Object {$_.StorageUsageCurrent -gt 51200}

Real-Time Use

Capacity planning.

 

6. Change Site Collection Administrator

Set-SPOUser `
-Site https://contoso.sharepoint.com/sites/HR `
-LoginName admin@contoso.com `
-IsSiteCollectionAdmin $true

Real-Time Use

Ownership changes.

 

7. Add Site Collection Admin

Set-SPOUser `
-Site https://contoso.sharepoint.com/sites/Projects `
-LoginName manager@contoso.com `
-IsSiteCollectionAdmin $true

 

8. Remove Site Collection Admin

Set-SPOUser `
-Site https://contoso.sharepoint.com/sites/Projects `
-LoginName manager@contoso.com `
-IsSiteCollectionAdmin $false

 

9. Lock a Site Collection

Read Only

Set-SPOSite `
-Identity https://contoso.sharepoint.com/sites/Finance `
-LockState ReadOnly

Real-Time Use

Compliance audits.

 

10. Unlock Site Collection

Set-SPOSite `
-Identity https://contoso.sharepoint.com/sites/Finance `
-LockState Unlock

 

11. Enable External Sharing

Set-SPOSite `
-Identity https://contoso.sharepoint.com/sites/Vendors `
-SharingCapability ExternalUserSharingOnly

Real-Time Use

Vendor collaboration.

 

12. Disable External Sharing

Set-SPOSite `
-Identity https://contoso.sharepoint.com/sites/HR `
-SharingCapability Disabled

 

13. Get Site Owners

Using PnP PowerShell:

Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/HR -Interactive

Get-PnPGroup

 

14. List All Site Members

Get-PnPGroupMembers -Identity "Members"

 

15. Create SharePoint Group

New-PnPGroup -Title "HR Approvers"

 

16. Add User to Group

Add-PnPGroupMember `
-LoginName user@contoso.com `
-Identity "HR Approvers"

 

17. Remove User from Group

Remove-PnPGroupMember `
-LoginName user@contoso.com `
-Identity "HR Approvers"

 

18. Get All Document Libraries

Get-PnPList |
Where-Object {$_.BaseType -eq "DocumentLibrary"}

Real-Time Use

Library audits.

 

19. Create Document Library

New-PnPList `
-Title "SOP Documents" `
-Template DocumentLibrary

 

20. Upload File

Add-PnPFile `
-Path "C:\Documents\SOP001.docx" `
-Folder "Shared Documents"

 

21. Download File

Get-PnPFile `
-Url "/sites/HR/Shared Documents/SOP001.docx" `
-Path "C:\Backup" `
-AsFile

 

22. Create Custom Column

Add-PnPField `
-DisplayName "Department" `
-InternalName Department `
-Type Choice

 

23. Create Content Type

Add-PnPContentType `
-Name "SOP Document" `
-Group "Corporate Content Types"

Real-Time Use

ECM implementations.

 

24. Get List Items

Get-PnPListItem `
-List "SOP Documents"

 

25. Delete List Item

Remove-PnPListItem `
-List "SOP Documents" `
-Identity 10

 

26. Get Site Permissions

Get-PnPWebPermission

 

27. Export Site Permissions

Get-PnPWebPermission |
Export-Csv "C:\Reports\Permissions.csv" -NoTypeInformation

Real-Time Use

Security audits.

 

28. Get All Site Collections Report

Get-SPOSite -Limit All |
Select URL, Title, Owner, StorageUsageCurrent |
Export-Csv "C:\Reports\AllSites.csv" -NoTypeInformation

 

29. Find Inactive Sites

Get-SPOSite -Limit All |
Select Url, LastContentModifiedDate

Real-Time Use

Site lifecycle management.

 

30. Delete Site Collection

Remove-SPOSite `
-Identity https://contoso.sharepoint.com/sites/TestSite

 

31. Restore Deleted Site

Restore-SPODeletedSite `
-Identity https://contoso.sharepoint.com/sites/TestSite

 

32. Get Deleted Sites

Get-SPODeletedSite

 

33. Enable Versioning on Library

Set-PnPList `
-Identity "Documents" `
-EnableVersioning $true

 

34. Enable Major and Minor Versions

Set-PnPList `
-Identity "Documents" `
-EnableMinorVersions $true

 

35. Bulk Add Site Collection Admin

$Sites = Get-SPOSite -Limit All

foreach($Site in $Sites)
{
    Set-SPOUser `
    -Site $Site.Url `
    -LoginName admin@contoso.com `
    -IsSiteCollectionAdmin $true
}

Real-Time Scenario

Emergency administrative access across all sites.

 

36. Generate Storage Report

Get-SPOSite -Limit All |
Select Url,
StorageQuota,
StorageUsageCurrent |
Export-Csv "C:\Reports\Storage.csv" -NoTypeInformation

 

37. Bulk Check External Sharing

Get-SPOSite -Limit All |
Select Url, SharingCapability

 

38. Connect Using Modern Authentication

Connect-PnPOnline `
-Url https://contoso.sharepoint.com `
-Interactive

 

39. Get Hub Sites

Get-PnPHubSite

 

40. Register Hub Site

Register-PnPHubSite `
-Site https://contoso.sharepoint.com/sites/Corporate

 

Top 10 Most Frequently Used SPO Admin Tasks in Production

Task

Frequency

Site Creation

Daily

Permission Management

Daily

Site Collection Admin Changes

Daily

Storage Monitoring

Weekly

External Sharing Review

Weekly

Library Administration

Weekly

Metadata Management

Weekly

Site Reports

Weekly

Compliance Audits

Monthly

Site Cleanup

Monthly


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.