Wednesday, May 23, 2012

Retrieving License keys from Multiple vCenters

Retrieving License keys from Multiple vCenters:

AlanFeb2012_thumb_thumb1_thumb_thumb[1]
Posted by
Alan Renouf
Technical Marketing

A question I receive all the time is:

How can I list all license keys I have for all of my Virtual Centers in my Infrastructure ?

Luckily PowerCLI enables us to work with multiple vCenters all at one, we can connect to many vCenters or hosts and pull back information on all of these at the same time, to do this you need to set the PowerCLI Configuration to work in multiple mode and then you can connect to more than one vCenter at the same time, to do this see the following example:
SNAGHTMLc8e21f3
Once we are in multiple configuration mode we can then use Connect-VIserver on as many vCenters or hosts as you like, we can use this to connect to multiple vCenters with the same credentials or just list each one like below:
Connect to multiple vCenters with the same username and password:
Connect-VIServer VC1, VC2, VC3, VC4 –User Administrator –Password MyPa$word
Connect to multiple vCenters with different credentials:
Connect-VIServer VC1 –User Administrator1 –Password MyPa$word1
Connect-VIServer  VC2 –User Administrator2 –Password MyPa$word2
Connect-VIServer VC3 –User Administrator3 –Password MyPa$word3
Connect-VIServer VC4 –User Administrator4 –Password MyPa$word4
Once connected this information is stored in the $DefaultVIServers variable, this can easily be viewed at any time:
SNAGHTMLc96fa66
We are also easily able to run scripts against these connections, like for example the License script at the end of this post, this lists all license keys and their information for each vCenter:
(You will excuse me if I exclude the actual key)
SNAGHTMLcc99b96


The Code


# Set to multiple VC Mode
if(((Get-PowerCLIConfiguration).DefaultVIServerMode) -ne "Multiple") {
    Set-PowerCLIConfiguration -DefaultVIServerMode Multiple | Out-Null
}

# Make sure you connect to your VCs here
# Get the license info from each VC in turn
$vSphereLicInfo = @()
$ServiceInstance = Get-View ServiceInstance
Foreach ($LicenseMan in Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager) {
    Foreach ($License in ($LicenseMan | Select -ExpandProperty Licenses)) {
        $Details = "" |Select VC, Name, Key, Total, Used, ExpirationDate , Information
        $Details.VC = ([Uri]$LicenseMan.Client.ServiceUrl).Host
        $Details.Name= $License.Name
        $Details.Key= $License.LicenseKey
        $Details.Total= $License.Total
        $Details.Used= $License.Used
        $Details.Information= $License.Labels | Select -expand Value
        $Details.ExpirationDate = $License.Properties | Where { $_.key -eq "expirationDate" } | Select -ExpandProperty Value
        $vSphereLicInfo += $Details
    }
}
$vSphereLicInfo | Format-Table -AutoSize


Get notification of new blog postings and more by following VMware PowerCLI on Twitter: @PowerCLI

DIGITAL JUICE

No comments:

Post a Comment

Thank's!