How is the usage of commands if i am connected to multiple vCenters ?
Often i want to get the result of a get-command only for one vCenter although i am connected to multiple vCenters.
Do i have to disconnect / connect first in this case ?
There is no need to keep all your connections in separate variables, they are already stored in $defaultVIServers.
With a simple where clause you can retrieve the connection you want.
For example:
Get-VM -Server ($defaultVIServers | where {$_.Name -eq "vCenter1"})
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you are connected to multiple vCenter servers, but want to the Get command only return the results of one vcenter server, you can use the -Server parameter. Like in:
$VIServer = Connect-VIserver "MyvCenterServer" Get-VM -Server $VIserver
Regards, Robert
When you use the Multi option for DefaultVIServerMode you can use the -Server parameter on most cmdlets to specify on which connection you want to execute the cmdlet. No need to dicsonnect-connect all the time.
For example
Get-VM -Server $defaultVIServers[1]
will use the 2nd connection from the list.
You can check the multi setting with Get-PowerCLIConfiguration and change it with Set-PowerCLIConfiguration.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When you are connected to multiply VCenter servers, you can use the "-server VCENTER" paramter to specify the VCenter you need the information from.
No need for any connect or disconnect commands.
EDIT: too slow, crappy proxy in the office...
Nachricht geändert durch Paule83
This is a good option - now i only need a command switch to display numbers before the servernames of $global:DefaultVIServers 🙂
Maybe my example was not clear enough. Try it like this to use servernames:
$Production = Connect-VIserver "Production" $OTA = Connect-VIserver "OTA" Get-VM -Server $Production Get-VM -Server $OTA
Message was edited by: RvdNieuwendijk
There is no need to keep all your connections in separate variables, they are already stored in $defaultVIServers.
With a simple where clause you can retrieve the connection you want.
For example:
Get-VM -Server ($defaultVIServers | where {$_.Name -eq "vCenter1"})
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes,
i often work in foreign VMware-systems. In your approach i have to define the servernames first.
In Luc's i can use the listed servers immediatly. FYI : sometimes up to 10 vCenters.
I must say that I like Luc's solution also. Only if you use this construction more than once in one script, it will be faster to get the vCenter server object once at the beginning of the script instead of getting it every time again:
$vCenter1 = $defaultVIServers | Where-Object {$_.Name -eq "vCenter1"} Get-VM -Server $vCenter1 Get-VMHost -Server $vCenter1
Robert, both methods have their pros and cons.
Your method is indeed more optimal when you open all the vCenters at the beginning of the script and close them all again at the end of the script.
The method I showed is better if the script opens and closes vCenter or ESX(i) connections throughout the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nevertheless , you made a great job. All of your approaches were very helpful .
Thanks a lot to all for your fast responses.