Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Created August 2, 2023 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hishaamn/4ab6072bf47e812c548b424311b2e4c2 to your computer and use it in GitHub Desktop.
Save hishaamn/4ab6072bf47e812c548b424311b2e4c2 to your computer and use it in GitHub Desktop.
$dialogProps = @{
Title = "Version Lister"
Description = "The dialog allows the selection whether to see all versions or only the latest"
Width = 500
Height = 100
OkButtonName = "OK"
CancelButtonName = "Cancel"
Parameters = @(
@{ Name = "onlyLatest"; Value=$true; Title="Show only latest versions"; Editor="checkbox"; }
)
}
$result = Read-Variable @dialogProps
if($result -ne "ok") {
Exit
}
$items = $null
if($onlyLatest){
$allVersionItems = Get-Item . -Language * -Version *
$items = $allVersionItems.Versions.GetLatestVersion();
} else{
$items = $allVersionItems;
}
$processedItems = @();
$results = @();
foreach($item in $items){
Write-Host "Item $($item.Name) with Language $($item.Language) and version number $($item.Version.Number)"
$key = $item.Name + "-" + $item.Language + "-" + $item.Version.Number
if($processedItems -NotContains $key){
$properties = @{
ID = $item.ID
Name = $item.Name
Language = $item.Language
Version = $item.Version.Number
LastUpdated = $item.Fields["__Updated"].Value
LastUpdatedBy = $item.Fields["__Updated by"].Value
}
$results += New-Object psobject -Property $properties
$processedItems += $key
}
}
$results | Show-ListView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment