VMware Cloud Community
adrianallan
Contributor
Contributor

Connect-ViServer & Winforms

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?

Thanks

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership

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?

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership

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

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
adrianallan
Contributor
Contributor

Yes I am using WPF for the gui

It is a Add_Click Event:

$connbtn.Add_Click({

$OV = (Connect-VIServer viserver -NotDefault -Credential(Get-Credential))

}

0 Kudos
adrianallan
Contributor
Contributor

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.

0 Kudos
LucD
Leadership
Leadership

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.

For example

$mySrv = Connect-VIServer -Server xyz -NoDefault
$vms = Get-VM -Server $mySrv
...
Connect-VIServer -Server xyz
$vms = Get-VM
...

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos