XenDesktop 7 comes with a flexible delegated administration model that provides role and object-based control. Out of the box you get a number of built-in roles to choose from, but most editions support the creation of custom roles.

Custom roles allow you to adapt the built-in roles to fit your organisation’s needs; you can select exactly which permissions are right for each type administrative user.

Once you get the set of custom role permissions configured, you might want to transfer those roles to each XenDesktop site that you set up. The Studio user interface is good for selecting the permissions in the first place, but you might get tired of re-entering the information if you have many custom roles.

Surely there must be a way to do it in PowerShell?” I hear you ask. Not wanting to disappoint, here are some magic incantations that will do trick.

To access these PowerShell cmdlets you need to load the Delegated Administration Snapin from a PowerShell prompt:

<span class="code-keyword">Add-PSSnapin</span> Citrix.DelegatedAdmin.Admin.V1

Next we want to extract the custom roles into a simple file, in this case CSV (comma separated values):

$roles = <span class="code-keyword">Get-AdminRole</span> -BuiltIn $false | <span class="code-keyword">select</span> Id,Name,Description,@{Name="Permissions";Expression={$_.Permissions -join ","}}
$roles | <span class="code-keyword">Export-CSV</span> roles.csv

Then this snippet of PowerShell will import the file into the new site:

$roles = <span class="code-keyword">Import-CSV</span> roles.csv
$roles | %{
  $r = <span class="code-keyword">New-AdminRole</span> -Name $_.Name -Description $_.Description
  if ($_.Permissions -ne "") {
    <span class="code-keyword">Add-AdminPermission</span> -Role $_.Name -Permission $_.Permissions.Split(",")
  }
}

Naturally, you need to be a full administrator for the site to change the configurations of roles.

That’s it, and I hope you find it useful.

PowerShell hints:

  • %{ } is a short-hand for Foreach-Object.
  • select is an alias for Select-Object, and the hash table @{ } in the select creates a calculated property.