Last active
March 27, 2020 05:47
-
-
Save chrisobriensp/7741792 to your computer and use it in GitHub Desktop.
PS + CSOM to iterate webs/lists and set a property..
This file contains hidden or 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
. .\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