Skip to content

Instantly share code, notes, and snippets.

@NamedJason
Created December 9, 2015 19:19
Show Gist options
  • Save NamedJason/1e203ec60a46e001aade to your computer and use it in GitHub Desktop.
Save NamedJason/1e203ec60a46e001aade to your computer and use it in GitHub Desktop.
PowerShell Profile for Multiple vCenters
set-location E:\Scripts
$Shell = $Host.UI.RawUI
$size = $Shell.WindowSize
$size.width=80
$size.height=25
$Shell.WindowSize = $size
$size = $Shell.BufferSize
$size.width=80
$size.height=5000
$Shell.BufferSize = $size
$vcenters = @("sacvc1","sfvc1","sdvc1","lavc1") | sort
$vcenters += "cancel"
clear-host
if ((get-pssnapin vmware* -erroraction silentlycontinue).count -gt 0)
{
do{
cls
echo "Connect to vCenter?"
"="*20
$i = 0
$vcenters | foreach {write-host -nonewline "[";write-host -f yellow -nonewline "$i"; write-host "] $_";$i++}
"="*20
$selection = read-host "Selection"
if(!($selection)){$selection = "sacvc1"}
if ($selection -match "^\d+$"){$selection = $vcenters[$selection]}
} until ($selection -in $vcenters)
if ($selection -ne "cancel")
{
# echo "Connecting to $selection..."
write-progress -activity "Connecting to $selection" -status "connecting..."
connect-viserver $selection
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment