VMware Horizon Community
sjesse
Leadership
Leadership

Entitle Users to Desktops or Applicaitons with PowerCli 6.5

I'm trying to figure out how to entile user to a desktop pool user powercli to get around a bug I'm experiancing. I've got this far

Get-Module -ListAvailable *Vmware* | Import-Module

$hvserver=Connect-HVServer -Server euc-conn-wd01.ur.rochester.edu -User 'euc_automation_svc' -Password 'Password123!' -Domain 'UR'

$viewAPI=$hvserver.ExtensionData

$desktop_service_helper = New-Object VMware.Hv.DesktopService

$userEntitlementService = New-Object VMware.Hv.UserEntitlementService

$userEntitlementService.UserEntitlement_Create

I am just not grasping the api enough to proceed any farther. The api reference says

NAMETYPEDESCRIPTION
_thisManagedObjectReferenceA reference to the UserEntitlement used to make the method call.
baseUserEntitlementBase

attributes needed to add a user entitlement

View API - VMware API Explorer - VMware {code}

I'm trying to figure out how to add user@domain to desktop_pool_a. I'm pretty sure I need to look up the id for the desktop pool id.

Tags (2)
9 Replies
AjayNadakuditi
Contributor
Contributor

Hi,

I faced the same issue as you were then I stumbled up on this post - Automating VMware Horizon 7 with VMware PowerCLI 6.5 - VMware End-User Computing Blog

Loaded the module for advanced functions and with some tweaking, I could able to add user entitlement to desktop pools.  Probably, it might help you as well.  Good luck!

Reply
0 Kudos
ggordon
VMware Employee
VMware Employee

Hi,

We are coming up with some new advanced functions that will cover entitling users and should make things easier.

These will include:

New-HVEntitlement, Get-HVEntitlement and remove Remove-HVEntitlement.

These will allow you to entitle an AD user or group to a resource like a Desktop, Application or URL Redirection.

Example: New-HVEntitlement -User 'domain\administrator' -ResourceName 'Calculator' -ResourceType Application

The team are finishing up development on these and they should be merged up to the Github repository soon.

Regards,

Graeme

AjayNadakuditi
Contributor
Contributor

Thats great Graeme.  Look forward to the update on github.

Reply
0 Kudos
sh33
Contributor
Contributor

AjayNadakuditi, Can you share an example of what you did for the entitlement service?  In the linked example the heavy lifting is done by the get-hvmachinesummary cmdlet and then you can dig through the attributes to find information.  I haven't found a similar approach for finding and changing entitlements.  Global entitlements is an attribute we're not using.

Reply
0 Kudos
sh33
Contributor
Contributor

Hi Graeme,

Is there an update for this?

Reply
0 Kudos
ITJef
Enthusiast
Enthusiast

has this been added to the Github repository?

I am looking for a way to add a machine to a manual desktop pool and entitle a user to that machine via powercli.

Reply
0 Kudos
krish290785
Enthusiast
Enthusiast

I encountered the same situation during the development of a small application for my team. With a bit of struggle, I was able to figure out a way to add new user entitlement to the automated desktop pool Below is the code.

############ Retrieve the Desktop Pool ID ############

$queryservice = New-Object VMware.Hv.QueryServiceService

$querydesktopid_def = New-Object VMware.Hv.QueryDefinition

$querydesktopid_def.QueryEntityType = 'DesktopSummaryView'

$querydesktopid_def.filter = New-Object VMware.Hv.QueryFilterEquals -property @{'memberName'='desktopSummaryData.name'; 'value' = $poolname}

$querydesktopid_results = ($queryservice.QueryService_Query($hvserver.ExtensionData,$querydesktopid_def)).Results

$desktopId = $querydesktopid_results.Id

############ Retrieve the user information from AD and find out the Entity ID ############

$queryuserid_def = New-Object VMWare.Hv.QueryDefinition

$queryuserid_def.QueryEntityType = 'ADUserOrGroupSummaryView'

$queryuserid_def.Filter = New-Object VMware.Hv.QueryFilterEquals -property @{'memberName'='base.loginName'; 'value' = $user}

$queryuserid_results = $queryservice.QueryService_Query($hvserver.ExtensionData,$queryuserid_def).Results

$userid = $queryuserid_results.Id

############ Create User entitlement############

$userentitlement_base = New-Object VMware.Hv.UserEntitlementBase -Property @{'Resource'=$desktopId; 'UserOrGroup' = $userid}

$hvserver.ExtensionData.UserEntitlement.UserEntitlement_Create($userentitlement_base)

The second part to retrieve the $userid information from AD and find out Entity ID seems to be time consuming one. Since this would query the whole AD and would slowdown the overall script execution time. Not sure if this is an optimal way to do it OR a better way exists.

-Bala Krishna Gali If the above info is useful, please mark answer as correct or helpful.
ITJef
Enthusiast
Enthusiast

Oh this is great. I will test this and judge the performance.

I was able to create the script below that works also.

invoke-command -computername $connectionserver -scriptblock {

        param($vmname, $vmviewPool, $vmuser)

       

        $Username = 'ServiceAccount'

        $Password = 'xxxxxxx' | ConvertTo-SecureString -AsPlainText -Force

        $Credential = New-Object -TypeName pscredential -ArgumentList $Username,$Password

   

        add-pssnapin vmware.view.broker

        Get-Module -ListAvailable VMware* | Import-Module

        connect-hvserver localhost -Credential $credential

       

        #add machine to pool

        add-hvdesktop -pool $vmviewpool -machines $vmname

       

        #add user to VM In pool

        $userresult = get-user -name $vmuser 

        $usersid = $userresult.sid

        $vmresult = get-desktopvm -name $vmname

        $vmMachineID = $vmresult.Machine_id

        update-userownership -machine_id $vmMachineID -sid $usersid

        disconnect-hvserver localhost -confirm:$false

}   -ArgumentList $vmname, $vmviewPool, $vmuser

Reply
0 Kudos
krish290785
Enthusiast
Enthusiast

Yeah. The old view powercli cmdlets are easy and straight forward. For my case where remote-in to connection server is not an option, Need to struggle a bit with that view api stuff.

-Bala Krishna Gali If the above info is useful, please mark answer as correct or helpful.
Reply
0 Kudos