Skip to main content
PowerShellXenApp 6.5

PowerShell Script Creating XenApp Applications and AD Group

By October 1, 2013No Comments

I demonstrate here the bare-bones script that I needed on a recent project. Working with a hosting company that were venturing into hosted applications on XenApp. Essentially they were providing PAYG access to applications and needed AD groups for each published app. Users who belong to the correct group gain access to the published application.  Users are added to the correct group using a web front end but did not concern me for this part of the project. I just needed to publish the apps and create the correct group. This, of course, was going to be laborious and an obvious target for a simple script.

In this demo firstly I need to install the Active Directory PowerShell module. This can be done very slowly using the GUI Windows Feature, or as fast as lightening using PowerShell. It is your life and your choice.

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell

Simple!

For the demo I also need to allow script to run. this would normally be set in the GroupPolicy.

Set-ExecutionPolicy Remote-Signed

The script now follow. to accept parameter the script must start with the PARAM declaration.

Param(
 [string]$Name,
 [string]$Path,
 [string]$User,
 [string]$Server,
 )
 Import-Module ActiveDirectory
 Add-PSSnapin Citrix.XenApp.Commands
 New-ADGroup -name $("CTX-"+$Name) -path "cn=users,dc=coolidge,dc=net" -GroupScope 1
 Add-AdGroupmember -Identity $("CTX-"+$Name) -members $user
 New-XAApplication -BrowserName $Name -ApplicationType ServerInstalled `
 -Displayname $Name -CommandLineExecutable $path -ServerName $Server
 Add-XAApplicationAccount $Name $("CTX-"+$Name)
 Set-XAApplication $Name -Enabled $true

The script accepts 4 parameters

  • $Name for the name of the App and makes are part of the group name
  • $Path is the full path to the app executable
  • $User can be used to add in a test user account to the group
  • $Server represents the server that the app is published on. The script is easily adjusted for Worker Groups.

To run the script

./scriptname -Name CalcP -Path calc.exe -User CitrixAdmin -Server XA-1