PowerCLI-Example-Scripts
PowerCLI-Example-Scripts copied to clipboard
PowerCLI 7.11 machine_update issues
I am able to add a VM to ManualDesktop using Desktop_AddMachinesToManualDesktop service, however I am struggling with Assign a user to the VM created and added to the Desktop pool.
I am trying to used MachineService with Machine_Update option. The part of the code is attached below. The scripts in the github repository dont have examples to create VM and assign a user so raising this ticket.
Any help is appreciated!
I am trying to assign a user to a VM added to the Desktop pool.
$AddUserEntitlements=($queryService.queryservice_create($hvServices, $defn)).results[0].id
$VMBaseUpdate = New-Object VMware.hv.machinebase
$VMBaseUpdate.Name = $vmName
$VMBaseUpdate.DnsName = $vmName
$VMBaseUpdate.User = $AccessUserID
$VMBaseUpdate.Desktop = $desktopId
$VMUpdate = New-Object VMware.Hv.MachineInfo
$VMUpdate.Base = $VMBaseUpdate
$VMUpdate.Id = $vmID
$updateid = New-Object VMware.Hv.MapEntry
$updateid.key = 'id'
$updateid.value = $VMID
$updatebase = New-Object VMware.Hv.MapEntry
$updatebase.key = 'base'
$updatebase.value = $VMBaseUpdate.base
$vmupdates= @()
$vmupdates += $updateid
$vmupdates += $updatebase
$MachineService = New-Object VMware.Hv.MachineService
$MachineService.Machine_update($hvServices, $VMID, $vmupdates)
Error message after running last line :
PS C:\> $MachineService.Machine_update($hvServices, $VMID, $vmupdates)
Exception calling "Machine_Update" with "3" argument(s): "ExceptionType : VMware.Hv.UnexpectedFault
ErrorMessage : Encountered unexpected error during execution
CauseString : java.lang.IllegalArgumentException: Cannot get access group for non-assigned machines
CauseStackTrace : System.String[]
ErrorCode :
ErrorAttributes : "
At line:1 char:1
+ $MachineService.Machine_update($hvServices, $VMID, $vmupdates)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException