SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple sites where I have used site settings to add users to 'Site Collection Administrators' but when I get these site collections using code the 'SiteAdministrators' property returns null.

Powershell example

 $web =get-spweb "..."
 # returns vaild web

 #returns null

  #Error: cannot call method on null-valued expression

Solved it. For some reason when I run powershell my account is being given a different loginName which does not match the site collection administrators. I have changed this & I am receiving the correct information. Thank you for helping.

share|improve this question
Can you see any site administrator listed through UI ? – Muhammad Raja Apr 24 '13 at 17:32
Yes, users are listed in the ui. Both "site settings -> site collection administrators" and "site settings -> site permissions ->site collection administrators" – user13186 Apr 24 '13 at 17:40
up vote 0 down vote accepted

Make sure that $web is not null and that the URL being requested by Get-SPWeb resolves to a SharePoint site

share|improve this answer
Yes I am using a valid spweb – user13186 Apr 24 '13 at 17:41
Do you have values for $web.Site.Owner and $web.Site.SecondaryContact? – Dave Wise Apr 24 '13 at 17:51
When I look at the site collection using CA, yes. When I use powershell, no but the $web object is valid and I am running poweshell 'as administrator'. Out of the 3 sites I am testing with 1 had returned values originally but no longer – user13186 Apr 24 '13 at 18:11

Your Answer


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.