If I run Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite | Get-SPWeb I get back a list of all web sites including Central Administration. If I put this line in a script and run this script I get the following error message (both in 'normal' and in elevated mode):

PS C:\[...]> . allwebs.ps1
Get-SPWeb : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\[...]\allwebs.ps1:1 char:76
+ Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite | Get-SPWeb <<<<
    + CategoryInfo          : InvalidData (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], Unauthorize
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb

The account is in the farm administrators group, is sitecollection administrator and has full controll within all webs.

What is the difference between running the Cmdlets from command line and within a script?

  • when running the script in powershell are you opening it up as admin?
    – Ali Jafer
    Commented Dec 5, 2013 at 11:48
  • As I've already mentioned: The issue occurs when I run the script as a 'normal' user, as well as when I run it as an admin (elevated mode).
    – user20990
    Commented Dec 17, 2013 at 18:19

1 Answer 1


make sure that the file allwebs.ps1 has the correct permissions! goto the file, right click and select properties. Now click on security tab and then edit button. Make sure the correct accounts are there like the admin account.

Could you also show some of the powershell code? I presume that your opening up sharepoint 2010 shell managment and dragging droping the file and then hit enter?

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.