Sharepoint - SPSite.allwebs returns error

I think this is a straightforward permissions problem. Get-SPSite will allow you to retrieve a SPSite object (...at least a partial one) without having permissions to that site collection. But when you try to access the AllWebs collection it throws an error.

To validate this I create a new site collection and made someone other than me the primary and secondary site collection admins. I then ran Get-SPSite against that site collection and it return the SPSite object, but when I access the AllWebs collection it threw exactly the same error as you see above.


All permissions required to correct this error:

  • Site Collection administrator on the SPSite (whether given through Central Admin or Site Settings)
  • PowerShell scripting admin: add-spshelladmin domain\username
  • PowerShell scripting admin on the content databases: get-spcontentdatabase | add-spshelladmin domain\username

note that the powershell commands must be run by the farm account (or someone else who already has these permissions)