Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 176483

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

$
0
0

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)


Viewing all articles
Browse latest Browse all 176483

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>