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.

  • Can you see any site administrator listed through UI ? Commented Apr 24, 2013 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
    Commented Apr 24, 2013 at 17:40

1 Answer 1


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

  • Yes I am using a valid spweb
    – user13186
    Commented Apr 24, 2013 at 17:41
  • Do you have values for $web.Site.Owner and $web.Site.SecondaryContact?
    – Dave Wise
    Commented Apr 24, 2013 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
    Commented Apr 24, 2013 at 18:11

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.