Skip to content

Instantly share code, notes, and snippets.

@asadrefai
Created May 11, 2015 14:59
Show Gist options
  • Save asadrefai/c713eac79a1a7ea9e41f to your computer and use it in GitHub Desktop.
Save asadrefai/c713eac79a1a7ea9e41f to your computer and use it in GitHub Desktop.
Enable or Disable the version and folder creation on a SharePoint list using CSOM PowerShell
function Disable-VersioningOnList()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName
)
begin{
try
{
#get Client Object
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $credentials
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
#Retrieve List
$List = $context.Web.Lists.GetByTitle($listName)
$context.Load($List)
$context.ExecuteQuery()
}
catch
{
Write-Host "Error while getting context. Error -->> " + $_.Exception.Message -ForegroundColor Red
}
}
process{
try
{
# To disable use $false else if to enable use $true
$list.EnableVersioning = $false
$list.EnableFolderCreation = $true
$list.Update()
$context.ExecuteQuery()
Write-Host "Versioning disabled on " $List.Title " successfully" -ForegroundColor Green
}
catch
{
Write-Host "Error while disabling versioning. Error -->> " + $_.Exception.Message -ForegroundColor Red
}
}
end{
$context.Dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment