Hi LucD,
Edit: So I figured out how to get it to return to the top, however I'd like to know how to exactly pass the info on. So for example I have something like this:
$commands = {
$entities = Get-Folder -Type VM
1..($entities.Count) | %{
Write-Host "$_ - $($entities[$_ - 1].Name)"
}
$answer = 0
while (1..($entities.Count) -notcontains $answer){
$answer = Read-Host -Prompt "Select a folder (1-$($entities.Count))"
}
Write-Host "You selected $($entities[$answer - 1].Name)"
#Stuff below will ask you a question on if you want to continue or exit the script, depending on your answer it will loop back to the top of $commands or will disconnect from vCenter and exit the script
$continue = New-Object System.Management.Automation.Host.ChoiceDescription '&continue', 'Continue with selection'
$exit = New-Object System.Management.Automation.Host.ChoiceDescription '&return', 'return to top'
$options = [System.Management.Automation.Host.ChoiceDescription[]]($continue, $exit)
$title = 'Continue with selection or return to top?'
$message = 'Do you want to continue with the current folder selection or make a different selection'
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
if ($result -eq "0"){
$moveon
} else {
&$commands
}
}
&$commands
$moveon = Get-Folder -Name $($entities[$answer - 1].Name) | Get-VM | sort Name | Format-Table
So I've tried a couple different things on the last line, I've used $answer, what you see above and $entities, but none pipe out the info from the folder. So what do I put there to get the list of VM's in that folder? Also wanted to know how to select multiple options if possible since a script may update multiple VM's, hosts, etc.
One last edit: I noticed when I run this and select a certain folder and I hit C to continue it shows me VM's that aren't in the folder I selected. In fact it shows the same 2 VM's from whatever folder I select and none of the folders I select hold those VMs. Rather odd and not sure why that's happening.