The Citrix Desktop Delivery Controller PowerShell SDK provides a snap-in, XDCommands, for the Microsoft PowerShell v1.0 framework. The SDK consists of a number of “cmdlets” that allow you to script many of the administrative tasks you may need to perform on a regular basis.
Step by Step setting up your PowerShell / XenDesktop environment
- Install PowerShell 1.0 on the DDC (Desktop Delivery Controller)
- Download and Install Microsoft .NET Framework 3.5
- The PowerShell SDK is located on the XenDesktop 2.1 CD in the …\Support\DdcSdk folder. Run the installer XenDesktop_2_0_DDC_Powershell_SDK.msi
Installing the SDK registers the XdCommands snap-in assembly with the Microsoft PowerShell framework. The snap-in makes a number of new classes and “cmdlets” available to PowerShell scripts or interactive shell sessions.
To run scripts you may need to use the built-in “Set-ExecutionPolicy” cmdlet to adjust the PowerShell execution policy to a value such as “RemoteSigned“
- Start Powershell and set the Excecution Policy. Set-ExecutionPolicy RemoteSigned
- Change to the folder where the SDK is installed cd \Program Files\Citrix\Desktop Delivery Controller\Powershell
- Load the snap-in into the PowerShell Add-PSSnapin XdCommands
Alternatively, use the installed PowerShell console file, XdCommands.psc1, to start an interactive PowerShell shell session with the XdCommands snap-in pre-loaded. Citrix provides a shortcut on the Start menu to start such a session. This shortcut also runs the “XdAliases.ps1” PowerShell script that sets up aliases for most of the SDK cmdlets. This shortcut will not function properly until the PowerShell execution policy, as described above, is set appropriately.
Online help is available for all Desktop Delivery Controller SDK cmdlets. To obtain a list of cmdlets offered by the snap-in, run the built-in “Get-Command” cmdlet, as follows: Get-Command -psSnapin XdCommands
Online help for individual cmdlets is available using the built-in “Get-Help” cmdlet. For example, to view the online help for the “Get-XdDesktopGroup” cmdlet, run the following command: Get-Help Get-XdDesktopGroup
For an overview of all cmdlets provided by the SDK, view the “about_XdCommands” help topic. To view this information, run the following command: Get-Help about_XdCommands
Creating a new VM-based desktop group
Adding a virtual desktop to an existing VM-based desktop group
This command adds a new virtual desktop, hosted by a VM, to an existing VM-based desktop group. Before adding a VM to the group, you must create a mapping between the VMs host ID and Active Directory ID. To do this, run the Get-XdHostedMachine cmdlet to obtain a list of host IDs for VMs and assign Active Directory IDs to those VMs.
If host ID to Active Directory ID mappings have been created previously, run the following command:
Logging off a user from all current sessions, after sending a warning message
This command displays a warning message to all users whose names start with “christian” before logging them off. Note that in this example there is specified time period (10 seconds) before logoff occurs.
Adding a user to an existing desktop group
This command adds users in all groups whose names match “GroupName” to an existing desktop group.
# get all the groups whose name matches ‘GroupName’ (should be just one)
# Note could also be written as: