3

I'm writing a script which gets the version of an item given the URL. However I can't seem to get the versions.

$objFile = $web.GetFile($sitecollection+/ZB/Forms/DispForm.aspx?ID=5266)
        Write-host $objFile.MinorVersion

however this doesn't seem to bring back the right results. What is the right way to get the version based on the url being dispformid=x

1 Answer 1

3

This gives you the string label of the version:

$objFile.UIVersionLabel

This gives you the Major version:

$objFile.MajorVersion

This gives you the Minor version:

$objFile.MinorVersion

Edit: The code above works with documents. The following will work with list items:

Assuming you have the id of your list item (in your example that is: "x"), you can create the $list object, get the list item and get the version of the item.

$webUrl = "http://SiteUrl";
$web = Get-SPWeb $webUrl;
$list = $web.Lists["ZB"]
$list.GetItemById(x).Versions[0].VersionLabel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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