From eb212dc7289dea2e8cfba5deef54f6d2dc103a07 Mon Sep 17 00:00:00 2001 From: JakubPiegza <45433779+JakubPiegza@users.noreply.github.com> Date: Sun, 19 Jan 2020 16:50:46 +0100 Subject: [PATCH] Update ContentTypeManagement.ps1 --- .../ContentTypeManagement.ps1 | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/ContentTypeManagement.ps1 b/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/ContentTypeManagement.ps1 index 37e989a0..0093a916 100644 --- a/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/ContentTypeManagement.ps1 +++ b/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/ContentTypeManagement.ps1 @@ -3,47 +3,42 @@ # Created by Arleta Wanat, 2015 # -function Set-SPOListsContentTypesEnabled -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOListsContentTypesEnabled{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [bool]$ContentTypesEnabled -) + ) -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) $ctx.ExecuteQuery() -$Lists=$ctx.Web.Lists -$ctx.Load($Lists) -$ctx.ExecuteQuery() + $Lists=$ctx.Web.Lists + + $ctx.Load($Lists) + $ctx.ExecuteQuery() -Foreach($ll in $Lists) -{ - $ll.ContentTypesEnabled = $ContentTypesEnabled - $ll.Update() - + Foreach($ll in $Lists){ + $ll.ContentTypesEnabled = $ContentTypesEnabled + $ll.Update() - try - { - $ctx.ExecuteQuery() - Write-Host $ll.Title " Done" -ForegroundColor Green - } + try{ + $ctx.ExecuteQuery() + Write-Host $ll.Title " Done" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red + } - catch [Net.WebException] - { - - Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red - } - -} + } } @@ -68,4 +63,4 @@ $ContentTypesEnabled=$true -Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled \ No newline at end of file +Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled