How to read all the PropertyBags for a SharePoint Site Collection!
To get articles like this free in your inbox, subscribe to our newsletter.
This time I’m sharing a new script that allows to get all PropertyBags for a Site Collection in SharePoint 2013 You can download the script from the following link: How to read all property bags in a SharePoint Site Collection
#Script that gets all the property Bags in a SharePoint Site Collection using Client Side Object Model
# Required Parameters:
# -> $sUserName: User Name to connect to the SharePoint Site Collection.
# -> $sPassword: Password for the user.
# -> $sSiteUrl: SharePoint Online Site Url
$host.Runspace.ThreadOptions = “ReuseThread”
#Definition of the function that allows to read property bags in a SharePoint Site Collection
function ReadSiteCollection-PropertyBags
{
param ($sSiteColUrl,$sUserName,$sDomain,$sPassword)
try
{
#Adding the Client OM Assemblies
Add-Type -Path “<CSOM_Path>\Microsoft.SharePoint.Client.dll”
Add-Type -Path “<CSOM_Path>Microsoft.SharePoint.Client.Runtime.dll”
#SPO Client Object Model Context
$spCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
$spCredentials = New-Object System.Net.NetworkCredential($sUserName,$sPassword,$sDomain)
$spCtx.Credentials = $spCredentials
Write-Host “—————————————————————————-” -foregroundcolor Green
Write-Host “Reading PropertyBags values for $sSiteColUrl !!” -ForegroundColor Green
Write-Host “—————————————————————————-” -foregroundcolor Green
$spSiteCollection=$spCtx.Site
$spCtx.Load($spSiteCollection)
$spRootWeb=$spSiteCollection.RootWeb
$spCtx.Load($spRootWeb)
$spAllSiteProperties=$spRootWeb.AllProperties
$spCtx.Load($spAllSiteProperties)
$spCtx.ExecuteQuery()
$spPropertyBagKeys=$spAllSiteProperties.FieldValues.Keys
#$spoPropertyBagKeys
foreach($spPropertyBagKey in $spPropertyBagKeys){
Write-Host “PropertyBag Key: ” $spPropertyBagKey ” – PropertyBag Value: ” $spAllSiteProperties[$spPropertyBagKey] -ForegroundColor Green
}
$spCtx.Dispose()
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Required Parameters
$sSiteColUrl = “http://<SiteCollectionUrl>”
$sUserName = “<UserName>”
$sDomain=”<AD_Domain>”
$sPassword =””<AD_Domain>”
ReadSiteCollection-PropertyBags -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sDomain $sDomain -sPassword $sPassword
When running the script, you should get the following output in the PowerShell ISE output:
Happy CloudSharing!!
What you should do next…
1. Subscribe to our newsletter:
Subscribe to our newsletter below for the latest news, advice and thought-leadership for software professionals. Or visit our blog to browse our most recent articles.
2. Learn how virtual labs can grow your business:
To learn more about how CloudShare helps software organizations grow revenue, increase efficiency and improve quality, visit our resources page. You’ll be able to browser dozens of valuable white papers, eBooks, webinars, case studies, and brochures.
3. Get a FREE, no obligation demo:
Discover just how easy it is to create your cloud environment—in minutes! One of our friendly virtual labs experts will be happy to:
- Show you the platform in action
- Calculate pricing for your business
- Set you up with a 14-day free trial
- Answer any questions you have
- No pressure or obligation