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.