Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Last active March 27, 2020 05:47
Show Gist options
  • Save chrisobriensp/7741792 to your computer and use it in GitHub Desktop.
Save chrisobriensp/7741792 to your computer and use it in GitHub Desktop.
PS + CSOM to iterate webs/lists and set a property..
. .\TopOfScript.ps1
$enableVersioning = $true
$rootWeb = $clientContext.Web
$childWebs = $rootWeb.Webs
$clientContext.Load($rootWeb)
$clientContext.Load($childWebs)
$clientContext.ExecuteQuery()
function processWeb($web)
{
$lists = $web.Lists
$clientContext.Load($web)
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
Write-Host "Processing web with URL " $web.Url
foreach ($list in $web.Lists)
{
Write-Host "-- " $list.Title
# leave the "Master Page Gallery" and "Site Pages" lists alone, since these have versioning enabled by default..
if ($list.Title -ne "Master Page Gallery" -and $list.Title -ne "Site Pages")
{
Write-Host "---- Versioning enabled: " $list.EnableVersioning
$list.EnableVersioning = $enableVersioning
$list.Update()
$clientContext.Load($list)
$clientContext.ExecuteQuery()
Write-Host "---- Versioning now enabled: " $list.EnableVersioning
}
}
}
foreach ($childWeb in $childWebs)
{
processWeb($childWeb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment