VMware Cloud Community
DyJohnnY
Enthusiast
Enthusiast

Get-LicenseDataManager not available when adding PowerCLi 5.1 snappin to powershell

Hi,

I'm trying to run a script that will assign a license to one of my datacenter objects in vcenter 5.1. The code Is taken straight from vmware's official documentation, and I know it works.

However I found that I absolutely have to run the code by starting the PowerCLI icon (or better yet, the target of that icon), otherwise get-licensedatamanager commandlet will not work.

Until now I have used this code to add the VMware snappin, but now it seems the snapin is not enough.

function LoadSnapin{

param($PSSnapinName)
if (!(Get-PSSnapin | where {$_.Name -eq $PSSnapinName})){
Add-pssnapin -name $PSSnapinName }

}

LoadSnapin -PSSnapinName "VMware.VimAutomation.Core"

This is piece of code i'm trying ro run

#add licenses

$licenseDataManager = Get-LicenseDataManager

#Run a cmdlet that retrieves the hosts in which the hosts for which you want to use the bulk licensing feature are located.

$hostContainer = Get-DataCenter MyDatacenter

#You can also run a cmdlet that retrieves a cluster to use bulk licensing for all hosts in a cluster, or retrieves a folder to use bulk licensing for all hosts in a folder.

#Create a new LicenseData object and a LicenseKeyEntry object with associated type ID and license key.

$licenseData = New-Object VMware.VimAutomation.License.Types.LicenseData

$licenseKeyEntry = New-Object Vmware.VimAutomation.License.Types.LicenseKeyEntry

$licenseKeyEntry.TypeId = "vmware-vsphere"

$licenseKeyEntry.LicenseKey = Read-Host -Message "Enter license key to license any host in $($hostcontainer.Name)"

#Associate the LicenseKeys attribute of the LicenseData object you created in step 3 with the LicenseKeyEntry object.

$licenseData.LicenseKeys += $licenseKeyEntry

#Update the license data for the data center with the LicenseData object and verify that the license is associated with the host container.

$licenseDataManager.UpdateAssociatedLicenseData($hostContainer.Uid, $licenseData)

$licenseDataManager.QueryAssociatedLicenseData($hostContainer.Uid)

IonutN
0 Kudos
4 Replies
LucD
Leadership
Leadership

Do you have the VMware.VimAutomation.License pssnapin loaded ?

Do a

Get-PsSnapin


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
DyJohnnY
Enthusiast
Enthusiast

Hi,

Yes the snapin seems loaded, as I can use the "other commandlets" in powercli.

I just can't seem to use some of these new commandlets.

Here's the output of get-pssnapin

PS C:\> get-pssnapin *vmware* | ft

Name                           PSVersion            Description

----                           ---------            -----------

VMware.VimAutomation.Core      2.0                  This Windows PowerShell sna...

But I think I found the solution to my dillema. Just ran this from the vsphere PowerCLI link on my desktop (Windows 7 client)

PowerCLI C:\> Get-PSSnapin -name *vmware* | ft

Name                           PSVersion            Description

----                           ---------            -----------

VMware.VimAutomation.Core      2.0                  This Windows PowerShell ...

VMware.VimAutomation.License   2.0                  This Windows Powershell ...

VMware.DeployAutomation        2.0                  Cmdlets for Rule-Based-D...

VMware.ImageBuilder            2.0                  This Windows PowerShell ...

So it seems the license is a different snapin alltogether.

IonutN
0 Kudos
LucD
Leadership
Leadership

Exactly, that's what I meant.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mattandes
Enthusiast
Enthusiast

A quick and dirty way of adding all the snapins is do do the following:

Add-PSSnapin "VMware*"

That will load all of them. You'll more than likely have to rework your function if you want to use it. It looks like if your running PSv3 if you try to add a snapin that's already added you will not get an error like you do if you try to do the same thing in PSv2.

Blog: http://www.virtual-matt.net