Hi
I am trying to write a script that will deploy a VM from template.
It works just fine if i do it with constants or with Read-Host command.
But i would like to have a drop down menu for selecting the data stores, and here i got confused.
Does anybody know how to do that?
Thanks
There are no native PowerShell cmdlets to give you dropdown menus.
But it's not too difficult to use Windows Forms from your PS scripts.
You can use something like PrimalForms from Sapien, and they also offer a free community version, to visually develop your forms and PrimalForms will create the PowerShell code for you.
A somewhat elaborate example of what you can do with forms is my GPS application.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok
I managed to populate the drop down, and it holds the fields that i need, but i cant find a way to store the selected item in a variable.
Its always blank.
Is there a special variable for that , or some kind of a method?
Could you perhaps post part of your code ?
Would make it a bit easier to check
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use
$comboBox1.SelectedItem
or
$comboBox1.SelectedIndex
to get the option that was selected.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks,
Tried it, still empty.
I guess something is really bad in my code.
You have placed the GenerateForm function inside your main script.
Perhaps you can make things clearer with a layout like this
function GenerateForm{ ... } if ($global:defaultviservers) { ... GenerateForm $store = $comboBox1.SelectedItem New-VM ... sleep 10 Start-Vm ... } else{ [http://System.Windows.Forms.MessageBox|http://System.Windows.Forms.MessageBox]::Show(... }
Notice how I pick up the selected datastore name after the call to the GenerateForm function.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok, thanks
My problem was the context of the variables.
When i organized as you wrote it worked.
Thanks