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 dAccessException + 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?