Custom PowerShell Profile to Connect to One of Many vCenter Servers

One of my customers has many physical datacenters, each with its own vCenter server.  The servers are all connected via Linked Mode, which works fine in the GUI, but at the CLI I don't usually want to connect to every one of them.  Fortunately, connect-viserver doesn't do so unless you use the -AllLinked switch, so that's fine.  Unfortunately, I'm left in a position where I need to connect my PowerCLI session to any one of many vCenter servers, and I don't necessarily like typing that much or remembering that many server names.

Fortunately, I can address both of those points in one fell swoop, through PowerShell Profiles.  When you launch PowerShell, it simply applies the appropriate PowerShell Profile (aka. a script that you can use to customize your work environment) to that session and you're good to go.  So, I put together a customized PowerShell Profile for myself that presents me with a "Connect to vCenter" option and a little text driven menu.  I've got it set up so that it is a little dynamic; the menu options are all contained within the $vcenters variable.  In order to add new options, I just change the contents of that variable and it's good to go.  I've got it set up so that I can connect to a given vCenter by either typing its name or by using the appropriate number.  I've also got a default option built in; if the user (read: me) just presses "enter", it will connect to sacvc1 (that's buried a bit in the logic, in case you need to change that).

Since I was customizing my PowerShell profile, I also took advantage of the opportunity to make a few other changes to my PowerShell session.  Most importantly, I set the line buffer to 5000, so that I can scroll back through *many* lines of text in my command prompt.

Anyway, if you want to use this or customize it, go ahead!  Just follow the instructions in that PowerShell Profiles article, overwriting the appropriate Profile file with this one.  As always with scripts found on the internet, I advise you to take the time to fully understand this before using it and to test it thoroughly - just because it worked for me is no guarantee that it'll work for you!

Comments

Popular posts from this blog

PowerShell Sorting by Multiple Columns

Clone a Standard vSwitch from one ESXi Host to Another

Deleting Orphaned (AKA Zombie) VMDK Files