SharePoint Online: Get Site Owner using PowerShell
Requirement: Get SharePoint Online Site Owner using PowerShell
How to Check Site Owner in SharePoint Online?
You can find site owner SharePoint Online from SharePoint Online Admin Center.
Let's see the PowerShell script to get SharePoint Online site owners.
PowerShell to Get Site Owner in SharePoint Online:
Here is the SharePoint Online PowerShell to list site owners
Get Site Owner in SharePoint Online using PowerShell
Here is how to get site owners of all SharePoint Online sites.
You can export Site Owners information to CSV file as:
Get Site Owners of Office 365 Group Connected Sites
While the above scripts works fine with sites without Office 365 groups, We got to change the script a bit to get site owners of a Office 365 group connected site collections, as the site owners is set as group owner.
How to Check Site Owner in SharePoint Online?
You can find site owner SharePoint Online from SharePoint Online Admin Center.
- Sign in to SharePoint Online Admin Center (https://YourDomain-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx)
- Select the site collection you wish to get site owner from the site collections list >> From the ribbon, Click on "Owners" and then "Manage Administrators.
- On the "Manage Administrators" dialog box, You'll get the site owner or primary site collection administrator.
Let's see the PowerShell script to get SharePoint Online site owners.
PowerShell to Get Site Owner in SharePoint Online:
Here is the SharePoint Online PowerShell to list site owners
#Variables for Admin Center & Site Collection URL $AdminCenterURL = "https://crescenttech-admin.sharepoint.com/" $SiteURL = "https://crescenttech.sharepoint.com/sites/marketing" #Connect to SharePoint Online Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential) #sharepoint online powershell get site owner Get-SPOSite $SiteURL | Select Owner
Get Site Owner in SharePoint Online using PowerShell
Here is how to get site owners of all SharePoint Online sites.
$AdminCenterURL = "https://crescenttech-admin.sharepoint.com/" #Connect to SharePoint Online Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential) #Get Site owners of all site collections Get-SPOSite -limit ALL | Select URL, OwnerThis PowerShell script retrieves site owners from all site collections. If you want to change site owner, use: How to Change Site Owner in SharePoint Online using PowerShell?
You can export Site Owners information to CSV file as:
Get-SPOSite | Select URL, Owner | Export-CSV "C:\Temp\SiteOwners.CSV"
Get Site Owners of Office 365 Group Connected Sites
While the above scripts works fine with sites without Office 365 groups, We got to change the script a bit to get site owners of a Office 365 group connected site collections, as the site owners is set as group owner.
Import-Module Microsoft.Online.SharePoint.PowerShell Import-Module AzureAD #Variables for Admin Center & Site Collection URL $AdminCenterURL = "https://crescent-admin.sharepoint.com/" $SiteURL = "https://crescent.sharepoint.com/sites/purchase" #Get Credentials to connect $Cred = Get-Credential #Connect to SharePoint Online and Azure AD Connect-SPOService -url $AdminCenterURL -Credential $Cred Connect-AzureAD -Credential $Cred | Out-Null #Get the Site Collection $Site = Get-SPOSite $SiteURL #Get Group Owners $GroupOwners = (Get-AzureADGroupOwner -ObjectId $Site.GroupID | Select -ExpandProperty UserPrincipalName) -join "; " Write-host $GroupOwnersThis script retrieves all owners of the associated Office 365 group. Let's combine above and get site owners for all sites in the tenant:
#Variables for Admin Center $AdminCenterURL = "https://crescentintranet-admin.sharepoint.com" $CSVPath = "C:\Temp\SiteOwners.csv" #Get Credentials to connect $Cred = Get-Credential #Connect to SharePoint Online and Azure AD Connect-SPOService -url $AdminCenterURL -Credential $Cred Connect-AzureAD -Credential $Cred | Out-Null #Get all Site Collections $Sites = Get-SPOSite -Limit ALL $SiteOwners = @() #Get Site Owners for each site collection $Sites | ForEach-Object { If($_.Template -like 'GROUP*') { $Site = Get-SPOSite -Identity $_.URL #Get Group Owners $GroupOwners = (Get-AzureADGroupOwner -ObjectId $Site.GroupID | Select -ExpandProperty UserPrincipalName) -join "; " } Else { $GroupOwners = $_.Owner } #Collect Data $SiteOwners += New-Object PSObject -Property @{ 'Site Title' = $_.Title 'URL' = $_.Url 'Owner(s)' = $GroupOwners } } #Get Site Owners $SiteOwners #Export Site Owners report to CSV $SiteOwners | Export-Csv -path $CSVPath -NoTypeInformationThe site owner is automatically added as Site collection administrator of the site. If you want to get all site collection administrators, use: SharePoint Online: Get Site Collection Administrators using PowerShell
Great Post! Short and precise!!
ReplyDeleteDo you have an easy way or a way to get O365 groups as well?
ReplyDeleteSure, You can retrieve Office 365 group owners as in: Find All Office 365 Group Owners using PowerShell
DeleteHow do I get the last script output in a CSV?
ReplyDeleteScript has been updated to export site owners data to CSV!
DeleteExport SiteOwners list in a Hub and all associated sites
ReplyDeleteConnect-PnPOnline -Url https://contoso-admin.sharepoint.com -UseWebLogin
$items = [System.Collections.ArrayList]@()
Get-PnPHubSite | %{
$hub = $_
Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -UseWebLogin
Get-PnPHubSiteChild -Identity $_.SiteId.Guid | %{
$siteUrl = $_
Write-Host "site Url: $siteUrl" -ForegroundColor Cyan
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$site = Get-PnPSite
$web = Get-PnPWeb
Get-PnPGroup -AssociatedOwnerGroup | %{
$group = $_
Get-PnPGroupMembers -Identity $_.Id | %{
if($group.Title -ne $_.Title -and $_.Title -ne "System Account"){
$item = New-Object psobject
# $item | Add-Member NoteProperty -Name "Hub Id" -Value $hub.ID
$item | Add-Member NoteProperty -Name "Hub Title" -Value $hub.Title
$item | Add-Member NoteProperty -Name "Hub Url" -Value $hub.SiteUrl
$item | Add-Member NoteProperty -Name "Site Title" -Value $web.Title
$item | Add-Member NoteProperty -Name "Site Url" -Value $site.Url
$item | Add-Member NoteProperty -Name "Owners Group" -Value $group.Title
$item | Add-Member NoteProperty -Name "Owner" -Value $_.Title
$item | Add-Member NoteProperty -Name "Owner Email" -Value $_.Email
$items.Add($item)
}
}
}
}
}
$items | Export-Csv -Path "C:\temp\export-intranetsiteowners.csv"
Hello.
ReplyDeleteThank you for the script. Found that for SPO Communication Sites, the script is outputting the user(s) who are Site Admin as Site Owners. Can the script be modified to remedy this so that the users in the OOB Site Owners group show up properly in the exported CSV? Thank you!