Ensure_List_VersionHistory

Language:
PowerShell
Keywords:
SharePoint
Code Snippet

Function Ensure_List_VersionHistory( [Microsoft.SharePoint.SPList]$tList
                                  , $VersionHistory
                                  , $MajorVersions_Limit = 0
                                  , $MinorVersions_Limit = 0
                                  ) {
    if ($VersionHistory -eq 1 -and ($tList.EnableVersioning -ne $false -or $tList.EnableMinorVersions -ne $false)) {
        $tList.EnableVersioning = $false
        $tList.EnableMinorVersions = $false
        Write-Output([System.String]::Format("List [{0}] : Setting Version History [{1}]", $tList.Title, "No Versioning"))
        $tList.Update()
    }
    if ($VersionHistory -eq 2 -and ($tList.EnableVersioning -ne $true -or $tList.EnableMinorVersions -ne $false)) {
        $tList.EnableVersioning = $true
        $tList.EnableMinorVersions = $false
        if ($MajorVersions_Limit -ne $tList.MajorVersionLimit) {
            $tList.MajorVersionLimit = MajorVersions_Limit
        }
        Write-Output([System.String]::Format("List [{0}] : Setting Version History [{1}]", $tList.Title, "Major Versions"))
        $tList.Update()
    }
    if ($VersionHistory -eq 3 -and ($tList.EnableVersioning -ne $true -or $tList.EnableMinorVersions -ne $true)) {
        $tList.EnableVersioning = $true
        $tList.EnableMinorVersions = $true
        if ($MajorVersions_Limit -ne $tList.MajorVersionLimit) {
            $tList.MajorVersionLimit = MajorVersions_Limit
        }
        if ($MinorVersions_Limit -ne $tList.MajorWithMinorVersionsLimit) {
            $tList.MajorWithMinorVersionsLimit = $MinorVersions_Limit
        }
        Write-Output([System.String]::Format("List [{0}] : Setting Version History [{1}]", $tList.Title, "Major AND Minor Versions"))
        $tList.Update()
    }
} # Function Ensure_List_VersionHistory(...)


Created 2011-10-13
comments powered by Disqus
Login