I try to get all webs of an SPSite (via Powershell) on a SharePoint 2010. First I tried to get all the webs like this:

$site = Get-SPSite http://<url>
$webs = $site.AllWebs

Every time tried it i got an invocation exception. The user I used to get the webs is farmadministrator and sitecollectionadministrator. So I tried to get webs with elevated priviliges:

$site = Get-SPSite http://<url>
$webs = $site.AllWebs
Write-Host "Web count: $($webs.Count)"

But this just results in an empty output.

  • What error message you get? Commented Jan 2, 2017 at 9:58
  • $site.AllWebs : Exception has been thrown by the target of an invocation. + CategoryInfo : NotSpecified: (:) [], TargetInvocationException + FullyQualifiedErrorId : System.Reflection.TargetInvocationException
    – user63126
    Commented Jan 2, 2017 at 10:03

1 Answer 1


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)

SPSite.allwebs returns error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.