Forum Discussion

BarryAnderson's avatar
BarryAnderson
Brass Contributor
Feb 25, 2021
Solved

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

  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 t...
  • Kelly_LaForest_CDW's avatar
    Mar 16, 2023

    Hey Barry,
    Unfortunately, you must be a site collection administrator (SCA) of a site to be able to have that script work successfully.
    Being a Global Administrator does not grant you access to all SharePoint sites within your tenant.
    The Global Admin role allows you to add your account as a site collection administrator to all the sites in your tenant, enabling you to run this script and other scripts.

    Your script worked beautifully for me BTW as I am a SCA for all sites in my tenant. Thanks for sharing it. 

    If you need to add yourself as a secondary SCA to all sites, you can use: 

    Connect-PnPOnline -Url $SiteURL.Url -Interactive
    Set-SPOUser -Site $SiteURL.Url -LoginName $UserName -IsSiteCollectionAdmin $true


    Notes: 

    • It will add the user as a secondary site collection administrator and not overwrite existing administrators including the primary administrator.
    • It will work if you are not an Admin for the site but have the SharePoint admin role.