Hi All,
Im in the process of creating a powershell script that will set common settings for quick recovery of ESXi hosts. One of the things I'm looking to do is input the ESXi Licence key and set it via a powershell script. I guess it is pretty simple, but as a powershell noob I wouldnt know which method to use. Can anyone reccommend a way to do this?
Dilpz
The following script will allow you to set the license key.
$licMgr = Get-View LicenseManager $esx = Get-VMHost <ESXi-hostname> | Get-View $licKey = New-Object VMware.Vim.LocalLicenseSource $licKey.licenseKeys = <your-license-key-string> $licMgr.ConfigureLicenseSource($esx.MoRef, $licKey)
If your ESXi server is managed from a VC, you'll probably need to set/disable the features as well.
Let me know if you need that part of the script as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The following script will allow you to set the license key.
$licMgr = Get-View LicenseManager $esx = Get-VMHost <ESXi-hostname> | Get-View $licKey = New-Object VMware.Vim.LocalLicenseSource $licKey.licenseKeys = <your-license-key-string> $licMgr.ConfigureLicenseSource($esx.MoRef, $licKey)
If your ESXi server is managed from a VC, you'll probably need to set/disable the features as well.
Let me know if you need that part of the script as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc,
You are the man. That works a charm. If you dont mind, I would like to see the other parts of the script that let you set licenced features.
Thanks
Dilpz
Your ESXi server has 2 states, "Unlicensed" and "ESX Server Standalone".
You set either of these states as follows:
# Set ESX Server Standalone $licMgr.SetLicenseEdition($esx.MoRef, "esxBasic") # Set Unlicensed $licMgr.SetLicenseEdition($esx.MoRef, $null)
When the ESXi server is in "ESX Server Standalone" it will automatically pick up the features "SAN Usage", "iSCSI Usage" and "Up to 4-way virtual SMP"
These features can be disabled and enabled as follows
# Disable SAN Usage $licMgr.DisableFeature($esx.MoRef, "san") # Disable NAS Usage $licMgr.DisableFeature($esx.MoRef, "nas") # Disable iSCSI Usage $licMgr.DisableFeature($esx.MoRef, "iscsi") # Disable Up to 4-way virtual SMP $licMgr.DisableFeature($esx.MoRef, "vsmp") ... # Enable SAN Usage $licMgr.EnableFeature($esx.MoRef, "san") # Enable NAS Usage $licMgr.EnableFeature($esx.MoRef, "nas") # Enable iSCSI Usage $licMgr.EnableFeature($esx.MoRef, "iscsi") # Enable Up to 4-way virtual SMP $licMgr.EnableFeature($esx.MoRef, "vsmp")
But there is probably no point in enabling/disabling these features on an individual basis.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Looks like I spoke too soon. When trying to run the code to set the licence key the following command does not put anything into the $licmgr variable. It is just blank:
$licMgr = Get-View LicenseManager
Any idea what might be wrong?
Are you connected to the VC or the ESXi ?
When you are connected to the ESXi this won't work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
We are connected directly to the ESXi host. We do not manage our ESXi hosts via virtualcenter as we use the free edition. Is there any way of setting the licence key via powershell in this case?
Without the VC the scripts I gave won't work.
Afaik even if you connect your ESXi servers to the VC they are still free if you configure them as "Unlicensed".
But you will be able to use the VIC and/or VITK script to configure the ESXi servers.
Perhaps someone more knowledgeable with ESXi and licensing can comment on this ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I wouldn't say that I am more knowledgeable, but I believe this falls back to the free version not allowing writes via PowerCLI.
Dave Convery
VMware vExpert 2009
Careful. We don't want to learn from this.
Bill Watterson, "Calvin and Hobbes"
I think Dave might be right, if you're using the free version of ESXi 3.5u4 (u2,u3 should work), you only have read-only access using the VI API (PowerCLI,vCLI/RCLI,VI Perl Toolkit), no write operations (http://vmetc.com/2009/03/31/esxi-u4-ends-free-version-read-and-write-access-from-the-rcli/).
You'll usually get a fault.RestrictedVersion.summary if you try to perform any write operations against ESXi.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
If you find this information useful, please award points for "correct" or "helpful".
That's true but I don't think we are that far yet.
The question, for me at least, is if we add an ESXi to the VC and set it to "Unlicensed" it doesn't seem to have used any of the feature licenses.
On the other hand you can then use several options from the VC: shutdown, reboot, scan/remediate...
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference