Showing posts with label farm level property bag. Show all posts
Showing posts with label farm level property bag. Show all posts

Saturday, August 24, 2013

Power Shell script to delete SharePoint Property bag Values.

# Add Powershell Snapin

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

# Set the variable to removed from property bag

$RemovePropertyBag = "DBConString"

# Get the central admin URL to delete the Property bag value at farm level

$SiteUrl = Get-SPWebApplication -includecentraladministration | where { $_.DisplayName -eq "Sharepoint Central Administration v4" }

# Load Required Assemblies

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

[System.Reflection.Assembly]::Load("Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")


[System.Reflection.Assembly]::Load("Microsoft.Practices.SharePoint.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=ef4330804b3c4129")


 $site = New-Object Microsoft.SharePoint.SPSite($SiteUrl.URL)

# Get Service locator context and config Manager to set the site context

$serviceLocator = [Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator]::GetCurrent()

$configManager = $serviceLocator.GetInstance([Microsoft.Practices.SharePoint.Common.Configuration.IConfigManager])


$configManager.SetWeb($site.RootWeb);


 # Get Property Bag

$farmBag = $configManager.GetPropertyBag([Microsoft.Practices.SharePoint.Common.Configuration.ConfigLevel]::CurrentSPFarm)

# set the Value

$configManager.SetInPropertyBag($RemovePropertyBag, "", $farmBag)

write-host "Removing PropertyBag Values $RemovePropertyBag successful"