Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top