VTwinDude's Blog

rss

Thoughts and updates from VTwinDude


OK… script away ---

A friend of my (Jeremy) helped write this with me learning sometime back however I cleaned it up some. It is and was a great tool in another role I use to be in. I removed list items 4-9 as we used it to setup specific performance settings for a technology/vendor product, but you do not need it for this script to help you with setting up the VI side of things. I do know that some of the PowerCLI commands are older but we had older ESX/ESXI versions we needed to cover. Also we haven’t had time to redo it with newer commands.

We wrote this originally to help implement VI settings as and as overwrite/correct settings. So please test it. You are using this at your own risks.

There is a step in here at the beginning to kill all VC connections… I used it for testing…
Here is a few of the settings we targeted at each layer – single host or vCluster or vDC

Enable Firewall Port Settings
Disconnect Media Devices from VMs
Modify Syslog Settings
Create Persistent Scratch Location
Modify Domain Name and DNS
Modify NTP settings
Modify Storage Settings (add, scan, rename, mount NFS share)
Enter/Exit Host from Maintenance Mode
Connect, Disconnect ESXi Host from vCenter
Change Root Password
View ESXi Logs
Enable\Disable SSH
Modify Networking Global Settings
Modify Networking for vSwitch 0, 1, 2

I would like to ask if you modify or update the Script then please share it back with us.
Please provide feedback/comments so we can make it better and report any issues you find.

I am not a GURU at scripting.. I just like to get creative sometimes and scripting helps with applying that creativity quickly.

Download - PowerVIConfigurator_v2.txt

 

Thanks
@vTwindude

 


So I was asked how to audit the VMware license in use vs portal? Meaning what we have vs what VMWare portal says we have vs what are we using. License is a big cost for most. For me I was thinking for sure there is a tool to do a compare, hmmm not that I can find. Sure you can look in your VMware portal to see what you have paid for. However if you are in the middle of a migration/upgrade it could become a mess to see what you have and how much you have paid for. So the fun begins…
This is a very large organization with many different levels of license as well as versions. At that point I was asking if there’s a tool to compare what are allotted vs used vs portal. As you know license can be a mess to maintain but surely there’s a tool to do an audit, well not so fast. I did search the web however i did not see what I was looking for, however I was thinking, surely someone has done this. So I turned to my social media friends for help. I put out a twitt to ask about a script to put this information. Sure enough some folks started to point me to scripting, and someone had one…. Thanks Jonathan Meed.
Requirement is to gather the following:

·         Hostname
·         License key assigned to the host
·         Name of the VC managing the host
·         License type
·         Flexibility to collect the information for multiple Virtual Centers

So I got a script from Jonathan and massaged it some however I couldn’t get it to do what we needed. This was on me as I was trying to understand each piece of the script. Great Job Jonathan!
So I did a little reading:
API - https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.LicenseManager.html
Understanding ‘Functions’ - http://www.thomas-franke.net/including-scripts-functions-modules/ 

At this point I decided to just create a script. I asked a friend Matt Derk for some help, he knows scripting pretty good. In any case here is what we came up with and it works,,,, yay
Disclaimer – We tested against VC 5.5

First set the script to collect data from multiple virtual centers:
I saw an error at first so we worked through this to stop the prompting for invalid cert.

# Set to multiple VC Mode
if(((Get-PowerCLIConfiguration).DefaultVIServerMode) -ne "Multiple") {
    Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
}

Then we wanted to allow for inputting multiple hosts:
#Define VC hosts – IPs or FQDN
$VChosts = @(
"VC1.ron.com",
"VC1.ron.com",
"VC3.ron.com"
);
Write-Host "Connecting to VC Server(s)"

Then connect to the hosts: We didn’t really want to prompt so the script will use the session you are logged in with. If you want to use different creds, right click and choose ‘Run As’.

Connect-VIServer -Server $VChosts

Then we need to define some variables for the data we want to grab
#Define variables for license and host functions
#API - https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.LicenseManager.html

$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager

Now let’s throw in a function to do this work:

function Get-VMHostId($Name)
{
    $vmhost = Get-VMHost $Name | Get-View
    return $vmhost.Config.Host.Value
}
function Get-License($VMHostId)
{
    $details = @()
    $detail = "" |select LicenseKey,LicenseType,Host,VC,Total,Used,ExpirationDate
    $license = $licAssignMgr.QueryAssignedLicenses($VMHostId)
    $license = $license.GetValue(0)
    $detail.VC = ([Uri]$licAssignMgr.Client.ServiceUrl).Host
    $detail.Host = $license.EntityDisplayName
    $detail.LicenseKey = $license.AssignedLicense.LicenseKey
    $detail.LicenseType = $license.AssignedLicense.Name
    $detail.Total = $license.AssignedLicense.Total
    $detail.Used = $license.AssignedLicense.Used
    $details += $detail
    return $details
}

Now run this against all hosts and puke out the data to a file. The script is setup to create the path/folders if not there.

# Run Query Against All Hosts
$vmhosts = Get-VMHost
$details = @()
foreach ($vmhost in $vmhosts) {
    $vmhostname = Get-VMHostId $vmhost.name
    $detail = Get-License $vmhostname
    $details += $detail
}
$details
if(!(Test-Path -Path C:\Temp )){New-Item -ItemType directory -Path C:\Temp}
write-host "output being save to C:\Temp\Host-Licenseinfo.csv"
$details | Export-Csv -NoTypeInformation C:\Temp\Host-Licenseinfo.csv
 
I can assure you I’m no pro at this but hey it works…. J However it seems that the “expire date” is in a different area and couldn’t get it to work within one script so we created second one to grab that. I know it’s not ideal but a manual combine is better than none.
Sample output; now you can sort and do all kinds of things with the data.




 

 

 

 

 

I am sure others can make these better. Thanks for reading and happy auditing your license.

Thanks Matt & Jonathan for your time and consideration.  

 

Download script:  Licenseinfo-01.txt