Created
March 10, 2021 05:16
-
-
Save plamber/dfbb0999646921af2bf2f603b5f36f01 to your computer and use it in GitHub Desktop.
List all site collection owners with PnP-PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $tenant = "<PutYourTenantIdHere>" | |
| $env:ClientId = "<PUTYourAppIdHere>" | |
| $env:ClientSecret = "<PUTYourAppSecretHere>" | |
| $fileExportPath = "<PUTYOURPATHHERE.csv>" | |
| Connect-PnPOnline https://$tenant-admin.sharepoint.com -ClientId $env:ClientId -ClientSecret $env:ClientSecret | |
| $results = @() | |
| $sites = Get-PnPTenantSite | |
| $sites | ForEach-Object { | |
| $site = $_ | |
| Write-Host "Processing $($site.Url)" | |
| Connect-PnPOnline $site.Url -ClientId $env:ClientId -ClientSecret $env:ClientSecret | |
| $owners = Get-PnPSiteCollectionAdmin | |
| foreach($owner in $owners){ | |
| $results += [pscustomobject][ordered]@{ | |
| SiteUrl = $site.Url | |
| LoginName = $owner.LoginName | |
| Title = $owner.Title | |
| Email = $owner.Email | |
| } | |
| } | |
| } | |
| Write-Host "Exporting file to $fileExportPath..." | |
| $results | Export-Csv -Path $fileExportPath -NoTypeInformation | |
| Write-Host "Completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment