none
Error "Get-SPOUser : Access denied. You do not have permission to perform this action or access this resource" RRS feed

  • Question

  • Hi,

    I am using SharePoint Online & I have used the following Powershell script to get list of Site Collections that are accessible to a user. I am able to connect correctly using Connect-SPOService. However, I get error "Get-SPOUser : Access denied. You do not have permission to perform this action or access this resource". Please let me know the solution to the problem.

    $Creds = Get-Credential

    $site = 'https://xxxxx-admin.sharepoint.com'

    Connect-SPOService -Url $site -Credential $Creds

    $AllSites = Get-SPOSite -Limit All

    $users = @();

    foreach ($Allsite in $AllSites)
    {
    $AllUsers = Get-SPOUser -Site $AllSite.Url -Limit all | select DisplayName, LoginName, IsSiteAdmin
    $users += $AllUsers
    $AllUsers = $null
    #Write-Host $AllSite.Url "completed"
    }

    $users | Export-Csv -Path "C:\allusers.csv" -NoTypeInformation -Force

    $Data = Import-Csv "C:\allusers.csv"

    foreach($aUser in $Data)
    {
      if ($aUser.IsSiteAdmin -eq "True")
      {
        Write-Host $aUser.DisplayName $aUser.LoginName
      }
    }
    Tuesday, May 15, 2018 4:42 PM

All replies

  • Hi,

    It requires a site collection administrator to run The “Get-SPOUser” cmd, as what listed in this documentation:

    https://technet.microsoft.com/en-us/library/fp161385.aspx

    One quick workaround is, you can use your CSP credential to create a user as “Global admin” in this tenant, then run the cmd with this account should also work.

    Best regards,

    Carl Zhou

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, May 16, 2018 6:47 AM
  • Hi Carl,

    I am Global admin and get the same error when I try to use Get-SPOUser

    + CategoryInfo          : NotSpecified: (:) [Get-SPOUser], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerUnauthorizedAccessException,Microsoft.Online.SharePoint.PowerShell.GetSPOUser

    I read all global admins are in the group "Company Administrator". If in a site collection someone has deleted the group "company administrator", then there would be this error?

    Best regards

    Miriam



    • Edited by MEKri Wednesday, May 30, 2018 3:36 PM
    Wednesday, May 30, 2018 2:35 PM