Soldato
I've knock up some code, which creates an array and then presents objects within that array as a choice; however it presents a column name instead of a numbered index:
current output:
target output:
I'm almost there but not quite. Here is the code which runs and executes successfully but when choosing anything other than the default, the entire session name needs to be typed out.
$i is where I've tried to play with creating an index but without success when trying to plug it into System.Management.Automation.Host.ChoiceDescription
Any pointers, much appreciated.
TIA!
current output:
Code:
Which session do you wish to kill?
[] Session A [] Session B [?] Help (default is "Session A"):
Code:
Which session do you wish to kill?
[1] Session A [2] Session B [?] Help (default is "Session A"):
Code:
if($a.count -gt 1){
$title = "Session Selection"
$message = "Which session do you wish to kill?"
# Build the choices menu
$choices = @()
#$choicesarray = @()
#$i = 0
For($index = 0; $index -lt $a.Count; $index++){
$choices += New-Object System.Management.Automation.Host.ChoiceDescription ($a[$index]).DesktopGroupName, ($a[$index]).SessionState
#$i++
}
$options = [System.Management.Automation.Host.ChoiceDescription[]]($choices)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
$a = $a[$result]
}
Any pointers, much appreciated.
TIA!