Convenience Functions for Connecting to Multiple vCenters

In a large environment repeatedly connecting and disconnecting from groups of vCenters can be tedious so I created some helper functions and put them in my PowerShell profile.

Connect-VIServerGroup lab
Connect-VIServerGroup desktops
Disconnect-VIServerGroup lab
Function Connect-VIServerGroup {
	param (
		[String]$group = $(throw "A VI server group name must be specified.")
	)
 
	Connect-VIServer -Server (Get-VIServerList $group)
}
 
Function Disconnect-VIServerGroup {
	param (
		[String]$group = $(throw "A VI server group name must be specified.")
	)
 
	Disconnect-VIServer -Server (Get-VIServerList $group) -Confirm:$false
}
 
Function Get-VIServerList {
	param (
		[String]$group = $(throw "A VI server group name must be specified.")
	)
 
	switch ($group) {
		"lab" {"vclab01.local", "vclab02.local"}
		"servers" {"vc001.local", "vc002.local", "vc003.local", "vc004.local"}
		"desktops" {"vc005.local", "vc006.local", "vc007.local", "vc008.local"}
		default {throw "No VI server group named $group found."}
	}
}

Leave a Comment

Your email address will not be published.