If you have a lot of hosts that you connect to it can be frustrating to remember them all. Since I have this problem I wrote this function to help deal with it. If you use the VI Client, connections are stored in the registry. This function reads these entries and presents you with a menu where you can select the host you want to connect to. Hopefully the forum doesn't mangle the code too much. I copied this into my Initialize-VIToolkitEnvironment.ps1 file so I get it automatically on startup.
Here's what it looks like in action:
function Connect-Recent {
$local:ErrorActionPreference = "SilentlyContinue"
$recent = (Get-Itemproperty "hkcu:\software\vmware\VMware Infrastructure Client\Preferences").RecentConnections
if ($recent -eq $null) {
$recent = (Get-Itemproperty "hkcu:\software\vmware\Virtual Infrastructure Client\Preferences").RecentConnections
}
if ($recent -eq $null) {
write-host -fore red "No recent hosts defined."
return
}
$recents = $recent.split(",")
write-host -fore yellow "Your recently visited hosts are:"
$max = 10
if ($recents.length -lt $max) {
$max = $recents.length
}
for ($i = 1; $i -lt $max+1; $i++) {
write-host -n "["
write-host -n -f yellow "$i"
write-host "]", $recents[$i-1]
}
$selection = 0
while ($selection -gt $max -or $selection -lt 1) {
$selection = [int](read-host "Select a host to connect to")
}
write-host -fore yellow "Connecting to", $recents[$selection-1]
connect-viserver $recents[$selection-1]
$global:defaultVIServer = $defaultVIServer
}
Here's what it looks like in action:
PS C:\> connect-recent
[1] 10.16.83.242
[2] 10.21.10.80
[3] 10.16.83.241
[4] 192.168.217.130
[5] 192.168.217.135
[6] pmstaff-esx1.eng.vmware.com
[7] 10.17.25.73
[8] 192.168.217.131
[9] 192.168.217.129
[10] 10.16.83.240
Select a host: 1
Connecting to 10.16.83.242
There were one or more problems with the server certificate:
* The certificate's CN name does not match the passed value.