From 85cd2de4827115154e21c3bba4ca4d189f65ab04 Mon Sep 17 00:00:00 2001 From: JakubPiegza <45433779+JakubPiegza@users.noreply.github.com> Date: Thu, 30 Jan 2020 00:11:52 +0100 Subject: [PATCH] Update ListContentTypes.ps1 --- .../ListContentTypes.ps1 | 65 ++++++++----------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 b/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 index db6603cf..a18ba4af 100644 --- a/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 +++ b/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 @@ -3,58 +3,45 @@ # Created by Arleta Wanat, 2015 # -function Set-SPOList -{ -param ( - [Parameter(Mandatory=$true,Position=0)] +function Set-SPOList{ + param( + [Parameter(Mandatory=$true,Position=0)] [string]$ListName, - [Parameter(Mandatory=$true,Position=1)] + [Parameter(Mandatory=$true,Position=1)] [bool]$ContentTypesEnabled - ) + ) -$ll=$ctx.Web.Lists.GetByTitle($ListName) + $ll=$ctx.Web.Lists.GetByTitle($ListName) -$ll.ContentTypesEnabled = $ContentTypesEnabled - $ll.Update() - - try - { - $ctx.ExecuteQuery() - Write-Host "Done" -ForegroundColor Green - } - - catch [Net.WebException] - { - - Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red - } - + $ll.ContentTypesEnabled = $ContentTypesEnabled + $ll.Update() + try{ + $ctx.ExecuteQuery() + Write-Host "Done" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red + } } - - - -function Connect-SPOCSOM -{ - param ( - [Parameter(Mandatory=$true,Position=1)] +function Connect-SPOCSOM{ + param( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$AdminPassword, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] [string]$Url -) + ) - -$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() -$global:ctx=$ctx + $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() + $global:ctx=$ctx } - $global:ctx @@ -77,4 +64,4 @@ $ContentTypesEnabled =$false Connect-SPOCSOM -Username $Username -AdminPassword $AdminPassword -Url $Url -Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled \ No newline at end of file +Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled