I have put together a quick GUI to log into vcenter and when the user clicks connect it executes "connect-viserver $server -Notdefault -Credential(Get-Credential)
It will popup and get the input; the console screen will show the normal certs error but the session never shows as connected and therefore all the rest of the program fails?
Any tips? Timing issue? Can a wait task be used and how?
Can you give more information about the GUI? It looks like the output is redirected and is not going to the console. Error output is a different output stream and does go to the console. But where is the normal output going?
Perhaps you're running the GUI in another (implicit) namespace ?
Are you using WPF for the GUI ?
Run the rest of your script while you're in the form.
Have a look at my PSTop to see how this can be done.
Blog: LucD notes
I guess I don't fully understand the - options well enough.. I removed -notdefault option and it worked fine. I am not sure I like that but it will have to do for now unless sombody out there can help me understand the behaviour.
When you do a Connect-VIServer the indentification of that server (beit vCenter of ESX/ESXI server) is stored in the variable $defaultVIServers.
With the -NoDefault switch, the server is not stored in the $defaultVIServers variable.
That means you will have to pass the variable on most of the following PowerCLI cmdlets with the -Server parameter.
By default the other cmdlets take the last connected server for the other PowerCLI cmdlets.
$mySrv = Connect-VIServer -Server xyz -NoDefault $vms = Get-VM -Server $mySrv ... Connect-VIServer -Server xyz $vms = Get-VM ...
Blog: LucD notes