A few times in PowerGUI or generally I have needed the user to select a single entity so that I can use this entity further in the code to narrow down the output, with this in mind i created a quick PrimalForms form which can be used as a function and a single object selected, the below code can be used within GUI apps like PowerGUI or vEcoShell or just from the powershell prompt.
For example if you wanted to select just the VMs from one host you could present the user a nice GUI with all the hosts added to the dropdown box with the following simple code:
# Send the Hosts to the GUI function
Select-GUIObject "Host" (Get-VMHost)
# Get the VMs for the selected host
$SelObj | Get-VM | Out-GridView
So the GUI box presented from the Select-GUIObject would look like so:

Once the host was selected and the OK button was pressed the VMs would be returned in $selObj and a list of VMs can be gained as in the next line of code and the following output from Out-Gridview:

Other examples of this function can be used with Get-VM or Get-Datastore or whatever you like, this is one of the areas I have spoken to the people at Quest and I believe they may be making some improvements to PowerGUI & vEcoShell to make input easier.
The code: Continue reading →