Purpose:
To publish Notepad.exe in XenApp automatically using PowerShell script.
Pre-requisite:
Following are the prerequisites for setting up the environment to execute PowerShell script to publish application in XenApp:
- .Net Framework 3.5 SP1 {Download it from Microsoft website}
- Microsoft PowerShell 1.0 {Download it from Microsoft website}
- XenApp Command technology preview{Download it from citrix site: https://www.citrix.com/English/ss/downloads/details.asp?downloadId=1687620&productId=186#top} : These commands are a PowerShell Tool Pack that allows managing most aspects related to XenApp. They cover all of MFCOM functionality for features available in XenApp 5 and include functionality from both AMC and CMC.
Install all the above components in the given order onto the XenApp environment.
Solution:
Below script is the solution. It has five parts:
Script:
1: # ===============================================================
2: #
3: # AUTHOR: Mohd Aslam
4: # DATE : 6/22/2010
5: #
6: # COMMENT: This script publishes notepad in XenApp
7: #
8: # ===============================================================
9:
10: [void] [System.Reflection.Assembly]::LoadWithPartialName(
11: "System.Drawing")
12: [void] [System.Reflection.Assembly]::LoadWithPartialName(
13: "System.Windows.Forms")
14:
15: $objForm = New-Object System.Windows.Forms.Form
16: $objForm.Text = "Application publish information"
17: $objForm.Size = New-Object System.Drawing.Size(430,250)
18: $objForm.StartPosition = "CenterScreen"
19:
20: $objForm.KeyPreview = $True
21: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
22: {$x=$objTextBox.Text;$objForm.Close()}})
23: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
24: {$objForm.Close()}})
25:
26: $OKButton = New-Object System.Windows.Forms.Button
27: $OKButton.Location = New-Object System.Drawing.Size(190,190)
28: $OKButton.Size = New-Object System.Drawing.Size(75,23)
29: $OKButton.Text = "OK"
30: $OKButton.Add_Click(
31: {
32: $AppName=$objAppName.Text;
33: $AppLoc=$objAppLoc.Text;
34: $AppWD=$objAppWD.Text;
35: $AppUsers=$objAppUsers.Text;
36: $AppServers=$objAppServers.Text;
37: $objForm.Close()
38: }
39: )
40: $objForm.Controls.Add($OKButton)
41:
42: $CancelButton = New-Object System.Windows.Forms.Button
43: $CancelButton.Location = New-Object System.Drawing.Size(290,190)
44: $CancelButton.Size = New-Object System.Drawing.Size(75,23)
45: $CancelButton.Text = "Cancel"
46: $CancelButton.Add_Click(
47: {
48: $objForm.Close()
49: }
50: )
51: $objForm.Controls.Add($CancelButton)
52:
53: $objLabel = New-Object System.Windows.Forms.Label
54: $objLabel.Location = New-Object System.Drawing.Size(10,20)
55: $objLabel.Size = New-Object System.Drawing.Size(280,20)
56: $objLabel.Text = "Please enter the information in the space below:"
57: $objForm.Controls.Add($objLabel)
58:
59: $objLbl_AppName = New-Object System.Windows.Forms.Label
60: $objLbl_AppName.Location = New-Object System.Drawing.Size(10,40)
61: $objLbl_AppName.Size = New-Object System.Drawing.Size(160,20)
62: $objLbl_AppName.Text = "Application Name:"
63: $objForm.Controls.Add($objLbl_AppName)
64:
65: $objAppName = New-Object System.Windows.Forms.TextBox
66: $objAppName.Location = New-Object System.Drawing.Size(190,40)
67: $objAppName.Size = New-Object System.Drawing.Size(205,20)
68: $objForm.Controls.Add($objAppName)
69:
70: $objLbl_AppLoc = New-Object System.Windows.Forms.Label
71: $objLbl_AppLoc.Location = New-Object System.Drawing.Size(10,70)
72: $objLbl_AppLoc.Size = New-Object System.Drawing.Size(160,20)
73: $objLbl_AppLoc.Text = "Application Command Line:"
74: $objForm.Controls.Add($objLbl_AppLoc)
75:
76: $objAppLoc = New-Object System.Windows.Forms.TextBox
77: $objAppLoc.Location = New-Object System.Drawing.Size(190,70)
78: $objAppLoc.Size = New-Object System.Drawing.Size(205,20)
79: $objForm.Controls.Add($objAppLoc)
80:
81: $objLbl_AppWD = New-Object System.Windows.Forms.Label
82: $objLbl_AppWD.Location = New-Object System.Drawing.Size(10,100)
83: $objLbl_AppWD.Size = New-Object System.Drawing.Size(160,20)
84: $objLbl_AppWD.Text = "Working Directory:"
85: $objForm.Controls.Add($objLbl_AppWD)
86:
87: $objAppWD = New-Object System.Windows.Forms.TextBox
88: $objAppWD.Location = New-Object System.Drawing.Size(190,100)
89: $objAppWD.Size = New-Object System.Drawing.Size(205,20)
90: $objForm.Controls.Add($objAppWD)
91:
92: $objLbl_AppUsers = New-Object System.Windows.Forms.Label
93: $objLbl_AppUsers.Location = New-Object System.Drawing.Size(10,130)
94: $objLbl_AppUsers.Size = New-Object System.Drawing.Size(160,20)
95: $objLbl_AppUsers.Text = "Application Users*:"
96: $objForm.Controls.Add($objLbl_AppUsers)
97:
98: $objAppUsers = New-Object System.Windows.Forms.TextBox
99: $objAppUsers.Location = New-Object System.Drawing.Size(190,130)
100: $objAppUsers.Size = New-Object System.Drawing.Size(205,20)
101: $objForm.Controls.Add($objAppUsers)
102:
103: $objLbl_Server = New-Object System.Windows.Forms.Label
104: $objLbl_Server.Location = New-Object System.Drawing.Size(10,160)
105: $objLbl_Server.Size = New-Object System.Drawing.Size(160,20)
106: $objLbl_Server.Text = "Servers*:"
107: $objForm.Controls.Add($objLbl_Server)
108:
109: $objAppServers = New-Object System.Windows.Forms.TextBox
110: $objAppServers.Location = New-Object System.Drawing.Size(190,160)
111: $objAppServers.Size = New-Object System.Drawing.Size(205,20)
112: $objForm.Controls.Add($objAppServers)
113:
114: $objLbl_Server = New-Object System.Windows.Forms.Label
115: $objLbl_Server.Location = New-Object System.Drawing.Size(10,200)
116: $objLbl_Server.Size = New-Object System.Drawing.Size(180,20)
117: $objLbl_Server.Text = "*: Enter ';' separated data if any"
118: $objForm.Controls.Add($objLbl_Server)
119:
120: $objForm.Topmost = $True
121:
122: $objForm.Add_Shown({$objForm.Activate()})
123: [void] $objForm.ShowDialog()
124:
125: New-XAFolder Applications/Test
126:
127: New-XAApplication -BrowserName $AppName `
128: -ApplicationType "ServerInstalled" `
129: -DisplayName $AppName -FolderPath "Applications/Test" `
130: -Enabled $true `
131: -CommandLineExecutable $AppLoc `
132: -WorkingDirectory $AppWD `
133: -AnonymousConnectionsAllowed $false `
134: -AddToClientStartMenu $false `
135: -InstanceLimit "-1" `
136: -ColorDepth 1 `
137: -AudioRequired $false `
138: -ClientFolder "Test"`
139:
140: Add-XAApplicationAccount -BrowserName $AppName `
141: -Accounts $AppUsers.Split(";")
142:
143: Add-XAApplicationServer -BrowserName $AppName `
144: -ServerNames $AppServers.Split(";")
Save above script to some location with .ps1 extension. To Run above script, go to “Programs > Citrix > XenApp Commands” and click “Windows PowerShell with XenApp Commands (CTP2)” icon. It will launch PowerShell command prompt.
On the PowerShell command prompt, write script name with full location and click enter. Script will run and below screen will be displayed:
Enter all the required data and click “Ok”. For application users and servers, multiple data can be entered separated by “;”.
Following screen will be displayed containing information about the published icon.
To confirm the successful publish, go to access management console and see the published icon as:
–Finish–