SharePoint Online is Microsoft’s collaborative cloud platform for creating team sites, storing documents and managing permissions in a Microsoft 365 environment.
Installation and connection
Action PowerShell Command Install SharePoint module Install-Module -Name Microsoft.Online.SharePoint.PowerShell -ForceInstall PnP PowerShell Install-Module -Name PnP.PowerShell -ForceConnect (Admin) Connect-SPOService -Url https://tenant-admin.sharepoint.comConnect (PnP) Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/sitename -InteractiveVerify connection Get-SPOTenantDisconnect Disconnect-SPOService
What is PnP PowerShell?
PnP = “Patterns and Practices” - Community PowerShell module more powerful than Microsoft’s official SharePoint module.
PnP advantages:
More cmdlets : 600+ commands vs ~150 for the official module
More granular : Lists, libraries, item-level permissions management
Cross-platform : Works on Windows, Mac, Linux
Modern : Based on Microsoft Graph and REST APIs
Active community : Updated more frequently
Use PnP for: Fine-grained permissions management, complex automation, advanced scripts
Use SharePoint official for: Tenant administration, basic site management
Site management
Action Command List all sites Get-SPOSite -Limit AllSearch for a site Get-SPOSite -Filter "Url -like '*marketing*'"Create team site New-SPOSite -Url "https://tenant.sharepoint.com/sites/marketing" -Title "Marketing" -Owner "admin@tenant.com" -Template "STS#3"Create communication site New-SPOSite -Url "https://tenant.sharepoint.com/sites/news" -Title "News" -Owner "admin@tenant.com" -Template "SITEPAGEPUBLISHING#0"Modify site title Set-SPOSite -Identity "https://tenant.sharepoint.com/sites/marketing" -Title "Marketing Team"Delete site Remove-SPOSite -Identity "https://tenant.sharepoint.com/sites/oldsite" -Confirm:$falseRestore deleted site Restore-SPODeletedSite -Identity "https://tenant.sharepoint.com/sites/oldsite"
SharePoint roles and permissions
Default permission levels
Role Permissions Typical usage Owner Full site control Team administrators Member Read, write, delete Active collaborators Visitor Read only Consultants, guests Designer Member + list/page management Content managers Contributor Read, write (no delete) Standard users
Detailed permissions
Level Read Write Delete Administration Design Full Control Yes Yes Yes Yes Yes Design Yes Yes Yes No Yes Collaborate Yes Yes Yes No No Contribute Yes Yes No No No Read Yes No No No No
Permission management
Action Command View site permissions Get-PnPSiteCollectionAdmin -Connection $connAdd site administrator Add-PnPSiteCollectionAdmin -Owners "admin@tenant.com"Remove administrator Remove-PnPSiteCollectionAdmin -Owners "admin@tenant.com"Add user Add-PnPGroupMember -Group "Site Members" -LoginName "user@tenant.com"Remove user Remove-PnPGroupMember -Group "Site Members" -LoginName "user@tenant.com"List group members Get-PnPGroupMember -Group "Site Members"
Permission inheritance
# Break permission inheritance on a list
Set-PnPList - Identity " Documents " - BreakRoleInheritance - CopyRoleAssignments
# Restore permission inheritance
Set-PnPList - Identity " Documents " - ResetRoleInheritance
Microsoft Teams integration
Action Command/Interface Associate existing site to Teams Teams interface > Add a tab > SharePoint Access Teams files https://tenant.sharepoint.com/sites/teamname/Shared DocumentsView Teams-linked sites Get-SPOSite | Where-Object {$_.Template -eq "GROUP#0"}Create Teams team (creates site) Teams interface or New-Team (Teams module) Manage permissions via Teams Teams interface > Settings > Members
Teams site structure
SharePoint Teams Site
|-- Shared Documents (Default library)
|-- [Channel] - General (Automatic folder)
|-- [Channel] - Marketing (One folder per channel)
+-- Custom lists (if created)
Storage and quotas
Action Command View tenant storage Get-SPOTenant | Select StorageQuota,StorageQuotaAllocatedView site usage Get-SPOSiteContentMoveState -Identity "https://tenant.sharepoint.com/sites/marketing"Set site quota Set-SPOSite -Identity "https://tenant.sharepoint.com/sites/marketing" -StorageQuota 2048List sites > 1GB Get-SPOSite -Limit All | Where-Object {$_.StorageUsageCurrent -gt 1024} | Select Url,StorageUsageCurrent
Export and management scripts
Export site list
# Complete site export with details
Get-SPOSite - Limit All | Select Url , Title , Owner , Template , StorageUsageCurrent , LastContentModifiedDate |
Export-Csv - Path " C:\temp\SharePointSites.csv " - NoTypeInformation - Encoding UTF8
Export permissions by site
# Detailed permissions export script
$sites = Get-SPOSite - Limit All
$results = foreach ($site in $sites) {
Connect-PnPOnline - Url $site.Url - Interactive
$groups = Get-PnPGroup
foreach ($group in $groups) {
$members = Get-PnPGroupMember - Group $group.Title
foreach ($member in $members) {
[ PSCustomObject ] @ {
SiteUrl = $site.Url
SiteTitle = $site.Title
GroupName = $group.Title
MemberName = $member.Title
MemberEmail = $member.Email
MemberType = $member.PrincipalType
}
}
}
}
$results | Export-Csv - Path " C:\temp\SharePointPermissions.csv " - NoTypeInformation - Encoding UTF8
Bulk site creation via CSV
# Expected CSV format: SiteName,SiteUrl,Owner,Template
$sites = Import-Csv - Path " C:\temp\NewSites.csv " - Delimiter " ; "
foreach ($site in $sites) {
try {
New-SPOSite - Url $site.SiteUrl - Title $site.SiteName - Owner $site.Owner - Template $site.Template - Wait
Write-Host " Site created: $ ( $site.SiteName ) " - ForegroundColor Green
} catch {
Write-Host " Error creating $ ( $site.SiteName ) : $ ( $_ .Exception.Message ) " - ForegroundColor Red
}
}
Bulk add users
# CSV format: SiteUrl,UserEmail,Permission
$permissions = Import-Csv - Path " C:\temp\SitePermissions.csv " - Delimiter " ; "
foreach ($perm in $permissions) {
try {
Connect-PnPOnline - Url $perm.SiteUrl - Interactive
$groupName = switch ($perm.Permission) {
" Read " { " Site Visitors " }
" Contribute " { " Site Members " }
" FullControl " { " Site Owners " }
}
Add-PnPGroupMember - Group $groupName - LoginName $perm.UserEmail
Write-Host " Added $ ( $perm.UserEmail ) to $ ( $perm.SiteUrl ) " - ForegroundColor Green
} catch {
Write-Host " Error adding $ ( $perm.UserEmail ) : $ ( $_ .Exception.Message ) " - ForegroundColor Red
}
}
Common site templates
Template Code Usage Team site STS#3Standard team collaboration Communication site SITEPAGEPUBLISHING#0Corporate news, announcements Blank site STS#1Custom site from scratch Enterprise Wiki WIKI#0Knowledge base Document Center BDR#0Advanced document management
Common troubleshooting
Problem Solution Access denied Check permissions, inheritance, AD/Entra groups Slow site Check library size, item count, views Mobile not working Enable “Allow mobile apps” in settings OneDrive sync fails Reset client, check special characters Quota exceeded Increase quota or clean up old versions