Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First of all sorry if this is an obvious question, I searched a lot but can't find the solution.

When I open an spsite in powershell like this:

 $spsite = Get-SPSite "https://adress"

And then I try to get all the webs like so

 $spsite.allwebs

I get the following error:

$spsite.allwebs : Exception has been thrown by the target of an invocation
+ CategoryInfo          : NotSpecified: (:) [], TargetInvocationExcept
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException

I don't understand what I am doing wrong, on my other SP server this works fine.

Thanks in advance,

Edit To be more clear about my problem I will post 2 screenshots Here you can see that I am logged in as sp_admin and I am primary admin in the site collection.

enter image description here

Here you see the commands I execute and the error I get.

enter image description here

Edit 2 $spsite.gettype output:

PS C:\Users\sp_admin> $spsite.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    SPSite                                   System.Object
share|improve this question
    
I'm assuming the first powershell line should be $spsite = Get-SPSite "https://address", right? –  user298 Aug 3 '11 at 12:31
    
@user298 yes sorry i will edit that ;) –  nldev Aug 3 '11 at 12:50
    
Please post full stack trace –  Anders Rask Aug 3 '11 at 16:26
    
What does $spsite.gettype() outputs? –  Janis Veinbergs Aug 5 '11 at 12:24
    
@Janis Veinbergs Added the output to the main question. –  nldev Aug 8 '11 at 6:51
show 1 more comment

3 Answers 3

up vote 4 down vote accepted

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.

share|improve this answer
1  
Okay that is strange, when i change myself to be the primary site collection administrator i still get the same error. I am logged in under the correct account. Any ideas? –  nldev Aug 4 '11 at 12:10
    
Could be a remoting issue or maybe even the dreaded UAC. Are you running this on a SP server in the farm hosting the site you are running the Get-SPSite against or are you doing this remotely? –  Rob D'Oria Aug 4 '11 at 17:35
    
First of all thanks for the help, i uploaded some images in my main post, i am logged in as admin, i am local admin, i am primary site admin, i am running it on the machine that runs the central admin. –  nldev Aug 5 '11 at 9:58
1  
It was a permissions problem, i logged in using sp_farm and everything worked fine. I think the difference was in the db_creator and db_securityadmin roles, but do not know for sure, but for future reference thry that! –  nldev Aug 9 '11 at 11:21
4  
To use the shell the user must have special previliges. In SharePoint 2010 you can use the add-shelladmin cmdlt: technet.microsoft.com/en-us/library/ee806878.aspx#section3 I think your reference to the missing db permissions is the right way to go. –  Marco Scheel Aug 10 '11 at 14:34
show 1 more comment

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)

share|improve this answer
    
Just had the same issue, the third bullet here worked for me. –  James Love Jul 10 at 11:24
add comment

The syntax is correct. Do you access to all sites in the site collection with the user that is executing the powershell prompt? Might be an access denied thing on one of the sites...

share|improve this answer
    
I run as the farm admin, is that the right way? –  nldev Aug 3 '11 at 12:51
    
Yeah, sounds good. Sorry, so I have no idea... –  Bernd Rickenberg Aug 3 '11 at 13:08
    
x2 The syntax works on my box, displays all the webs. Did you get an incident ID with the error? –  Tom Halladay Aug 3 '11 at 13:48
    
Nope, this is the complete error as i got it. Any ideas? –  nldev Aug 3 '11 at 13:51
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Karthik Jaganathan Jun 17 at 5:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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