Add case sensitive Property Bag key using powershell

Recently , i was trying to add property bag key which is case sensitive.

Code Sample

$siteurl = “http://something”;

$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$rootWeb = $site.RootWeb

$rootWeb.Properties.Add(“CaseSenSitiveKey”, “Value1”);
$rootWeb.Properties.Update();

Write-Host $rootWeb.Properties[“CaseSenSitiveKey”]
Write-Host “Using All Properties”
Write-Host $rootWeb.AllProperties[“CaseSenSitiveKey”]

Here  i was using Properties.Add() function , and tried to get property back to see its  added. but when above script executes, only $rootWeb.Properties[“CaseSenSitiveKey”]  line return results as “Value1”.

SharePoint designer  shows that property key added in simple case.

Capture1

By search on web i found  this article it explains about two approach of adding property bag values and their differences .Even though it explains about c# code it also valid with PS scripts.

$siteurl = “http://something”;

$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$rootWeb = $site.RootWeb

$rootWeb.AllProperties.Add(“CaseSenSitiveKey”, “Value1”);
$rootWeb.Update();

Write-Host $rootWeb.Properties[“CaseSenSitiveKey”]

Write-Host $rootWeb.AllProperties[“CaseSenSitiveKey”]

Using AllProperties.Add() function i managed to add case sensitive property key as per my requirement.

Capture3

Hope This help some one to resolve problems comes with day today share point development.