Report on all sites a user is an owner or member of

%3CLINGO-SUB%20id%3D%22lingo-sub-2166024%22%20slang%3D%22en-US%22%3EReport%20on%20all%20sites%20a%20user%20is%20an%20owner%20or%20member%20of%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2166024%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20create%20an%20output%20which%20lists%20all%20the%20sites%20a%20named%20user%20is%20the%20owner%20or%20a%20member%20of.%26nbsp%3BI%20thought%20this%20would%20be%20fairly%20simple%20in%20PowerShell.%20I%20could%20simply%20iterate%20through%20all%20sites%2C%20read%20the%20memberships%20and%20filter.%20However%2C%20am%20running%20into%20difficulty%20with%20the%20Get-SPOUser%20command%20as%20it%20tells%20me%20my%20Global%20Admin%20account%20does%20not%20have%20permission%20to%20list%20the%20site%20members.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EError%20for%20Get-SPOUser%20(running%20as%20Global%20Admin)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-SPOUser%20%3A%20Access%20denied.%20You%20do%20not%20have%20permission%20to%20perform%20this%20action%20or%20access%20this%20resource.%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EScript%20I%20started%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23%20Connect%20to%20SharePoint%20Online%20Admin%0AWrite-host%20%22Connecting%20to%20Admin%20Center...%22%20-f%20Yellow%0AConnect-SPOService%20-Url%20%24Admin_Url%0A%0A%23%20Get%20all%20site%20collections%0AWrite-host%20%22Getting%20All%20Site%20collections...%22%20-f%20Yellow%0A%24Sites%20%3D%20Get-SPOSite%20-Limit%2010%20%23%20-Limit%20ALL%0A%0AForEach(%24Site%20in%20%24Sites)%20%7B%0A%20%20%20%20Write-host%20%22Getting%20Users%20from%20Site%20collection%3A%22%24Site.Url%20-f%20Yellow%0A%20%20%20%20Get-SPOUser%20-Limit%20ALL%20-Site%20%24Site.Url%20%7C%20Select%20DisplayName%2C%20LoginName%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20simpler%20or%20already%20baked%20way%20to%20achieve%20my%20request%3F%3C%2FP%3E%3CP%3EIf%20not%20how%20do%20I%20query%20site%20membership%20using%20Global%20Admin%20account%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2166024%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Contributor

 

I need to create an output which lists all the sites a named user is the owner or a member of. I thought this would be fairly simple in PowerShell. I could simply iterate through all sites, read the memberships and filter. However, am running into difficulty with the Get-SPOUser command as it tells me my Global Admin account does not have permission to list the site members.

 

Error for Get-SPOUser (running as Global Admin):

 

Get-SPOUser : Access denied. You do not have permission to perform this action or access this resource.

 

 

Script I started:

 

# Connect to SharePoint Online Admin
Write-host "Connecting to Admin Center..." -f Yellow
Connect-SPOService -Url $Admin_Url

# Get all site collections
Write-host "Getting All Site collections..." -f Yellow
$Sites = Get-SPOSite -Limit 10 # -Limit ALL

ForEach($Site in $Sites) {
    Write-host "Getting Users from Site collection:"$Site.Url -f Yellow
    Get-SPOUser -Limit ALL -Site $Site.Url | Select DisplayName, LoginName
}

 

 

Is there a simpler or already baked way to achieve my request?

If not how do I query site membership using Global Admin account?

0 Replies