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 just created a new WebApplication & Site Collection in sharepoint.

Note : WebApplication uses Claims Authentication mode, Custom Trusted Identity Provider for my application.

In powershell when i try to access $site.RootWeb.AllProperties it is returning null

$site.RootWeb.AllProperties.Add("a", "1")

You cannot call a method on a null-valued expression. At line:1 char:21

+ $site.RootWeb.AllProperties.Add <<<< ("a","1")

+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException

+ FullyQualifiedErrorId : InvokeMethodOnNull

Does anyone knows why this occurs?

share|improve this question
This happens only on web applications with claims based authentication and not on integrated authentication. – BalajiG Jan 7 '13 at 6:54

This blog provides a good overview of how to work with the SPWeb property bag while also providing links to MSDN.

The root of your problem, it seems, is that you are doing SPWeb.AllProperties.Add() instead of SPWeb.AddProperty()

share|improve this answer
Am getting the same error. See the reflected AddProperty method below public void AddProperty(object key, object value) { this.AllProperties.Add(key, value); } PS C:\windows> $w.AddProperty("a","1") Exception calling "AddProperty" with "2" argument(s): "Access is denied. (Excep tion from HRESULT: 0x80070005 (E_ACCESSDENIED))" At line:1 char:15 + $w.AddProperty <<<< ("a","1") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException – BalajiG Jan 7 '13 at 6:30
Hey at least this approach exposed an access denied error which is much easier to troubleshoot :) – SpartanDonut Jan 7 '13 at 14:52
I got this access denied error before also while trying the same in a console application also. Yes really that helped a lot in analysing the issue. Thanks reaaaaally a lot for your help. – BalajiG Jan 8 '13 at 10:30
up vote 1 down vote accepted

Getting the site using Elevated Privileges fixed the problem

PS C:\windows> [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({$s = get-spsite "http://balajig-01"})
PS C:\windows> $s.RootWeb.AllProperties

Name                           Value
----                           ----- 
vti_associatemembergroup       5
vti_associatevisitorgroup      4
vti_associategroups            5;4;3
vti_createdassociategroups     3;4;5
vti_approvallevels             Approved Rejected Pending\ Review
vti_categories                 Travel Expense\ Report Business Competition G...
vti_associateownergroup        3
vti_defaultlanguage            en-us

Thanks anyways

share|improve this answer
This would make sense. I'm generally running powershell as site collection or farm admin and don't have a need for that. Good catch. – SpartanDonut Jan 7 '13 at 14:51

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.