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

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 "..."
 $web
 # returns vaild web

 $web.Site.RootWeb.siteadministrators
 #returns null

  $web.Site.RootWeb.SiteAdministrators.Add($user)
  #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
add comment

1 Answer

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
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.