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