-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
How to read Property Bags using CSOM
How to read Property Bags for a SharePoint Site Collection using CSOM
- Loading branch information
Juan Carlos González
committed
Feb 6, 2015
1 parent
6cfdf66
commit 02c6909
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
SharePoint/Administration/CSOM/PS_ReadAllPropertyBags_CSOM.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
############################################################################################################################################ | ||
#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 | ||