A few things brought this post together. First is that Glen Sizemore of Get-Admin and I have co-submitted a “vSphere Automation 101 – PowerCLI” session to the VMworld 2011 CFP. We thought it’d be an excellent idea to share some of that content before hand.
The second, and just as important, is that I’m Lazy so in the same line as my other “Professionally Lazy” post, here is another 101 style post for PowerCLI. Basically I dislike typing out the names of every vCenter each time I need to connect to more than one. PowerCLI is flexible enough to allow you to connect to more than one at a time, so why not take advantage. As with everything in IT, there are multiple ways to eat the cat… or skin him or whatever:
Lots of vCenters in Connect String
This is the most straight forward of the bunch:
Connect-VIServer -Server vcenter01.provmware.com, vcenter02.provmware.com
Storing vCenters in an Array
Well, using a list like above, that’s a lot of typing, and other than blog posts, why type more than you have to? Another approach is to keep all of your vCenters in an array, and then connect to them all at once. This is a variation on the above in that it keeps your connect line short:
# Setup array with hosts
$hosts = @(
# Store your U&P
$user = "notTelling"
$password = "butNiceTry"
Connect-VIServer -Server $hosts -User $user -Password $password
Using a Menu
This was one of those “learn something new every day” features. As in, I the blog post surfaced about 6 minutes after I started typing this post up, and that is, the -Menu parameter of connect-viserver. Using their example:
PS C:\WINDOWS\system32\windowspowershell\v1.0> Connect-VIServer -Menu
Select a server from the list (by typing its number and pressing Enter):
WARNING: There were one or more problems with the server certificate:
* The X509 chain could not be built up to the root certificate.
* The certificate’s CN name does not match the passed value.
Name Port User
—- —- —-
vc41-ga.pc 443 powershell
With luck, this will get you a bit more familiar with PowerCLI and managing your environment, of any size. Stay tuned for more.