I have a PowerShell script that updates document libraries to make sure that versioning is enabled:

$list.EnableVersioning = $true

How can I check whether versioning is enabled before making the change, so that I don't keep updating the list unnecessarily? I tried the following, but the syntax is incorrect:

if (list.EnableVersioning -ne $true) { $list.EnableVersioning = $true }
  • 2
    Above code works if I remember to add the $ before list "($list..." – LFurness Jun 25 '12 at 14:58

If versioning on List is Enabled then perform changes:

  If ($list.EnableVersioning -eq $TRUE) 
     //perform changes

| improve this answer | |

This works in my environment


| improve this answer | |
  • 3
    This condition will assign $true to the EnableVersioning and evaluate to true regardless of the old value of EnableVersioning – Per Jakobsen Jun 25 '12 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.