-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathNew-CTXApplication.ps1
326 lines (288 loc) · 14.5 KB
/
New-CTXApplication.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#Requires -Version 5.0
<#
.SYNOPSIS
Creates a new published application
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
Requires the library script CitrixLibrary.ps1
Requires PSSnapIn Citrix*
.LINK
https://github.com/scriptrunner/ActionPacks/blob/master/Citrix/Applications
.Parameter SiteServer
[sr-en] Specifies the address of a XenDesktop controller.
This can be provided as a host name or an IP address
[sr-de] Name oder IP Adresse des XenDesktop Controllers
.Parameter ApplicationName
[sr-en] Name of the application (must be unique within folder)
[sr-de] Name der Anwendung (eindeutig innerhalb des Ordners)
.Parameter CommandLineExecutable
[sr-en] Name of the executable file to launch
[sr-de] Dateiname der auszuführenden Anwendung
.Parameter CommandLineArguments
[sr-en] Command-line arguments to use when launching the executable
[sr-de] Befehlszeilenargumente, die beim Starten der ausführbaren Datei verwendet werden
.Parameter ApplicationGroup
[sr-en] Application group this application should be associated with
[sr-de] Anwendungsgruppe, der diese Anwendung zugeordnet wird
.Parameter DesktopGroup
[sr-en] Desktop group this application should be associated with
[sr-de] Desktopgruppe, der diese Anwendung zugeordnet wird
.Parameter ApplicationType
[sr-en] Type of the application
[sr-de] Typ der Anwendung
.Parameter BrowserName
[sr-en] Internal name for this application
[sr-de] Interner Name der Anwendung
.Parameter ClientFolder
[sr-en] Folder that the application belongs to as the user sees it
[sr-de] Anwendungskategorie
.Parameter CpuPriorityLevel
[sr-en] CPU priority for the launched process
[sr-de] CPU Priorität der Anwendung
.Parameter Description
[sr-en] Description for the application
[sr-de] Beschreibung der Anwendung
.Parameter Enabled
[sr-en] Application can be launched by end users
[sr-de] Anwendung kann von Endbenutzern gestartet werden
.Parameter Visible
[sr-en] Application is visible to users Y/N
[sr-de] Anwendung ist für Benutzer sichtbar J/N
.Parameter HomeZoneOnly
[sr-en] Specifies whether if the preferred zone for launching the application is its home zone but no machine is available from that zone then the launch fails
[sr-de] Start schlägt fehl, wenn die bevorzugte Zone zum Starten der Anwendung die Home-Zone ist, aber kein Rechner aus dieser Zone verfügbar ist
.Parameter IconFromClient
[sr-en] The app icon should be retrieved from the application on the client
[sr-de] App-Symbol soll von der Anwendung auf dem Client abgerufen werden
.Parameter IgnoreUserHomeZone
[sr-en] When launching the application and the user has a home zone specified then the user's home zone preference should be ignored
[sr-de] Wenn die Anwendung gestartet wird und der Benutzer eine Homezone angegeben hat, sollte die Einstellung der Homezone des Benutzers ignoriert werden
.Parameter LocalLaunchDisabled
[sr-en] When launching a published application from within a published desktop, do not launch the application in that desktop session
[sr-de] Wenn eine veröffentlichte Anwendung aus einem veröffentlichten Desktop heraus gestartet wird, startet die Anwendung nicht in dieser Desktop-Sitzung
.Parameter MaxPerMachineInstances
[sr-en] Maximum allowed concurrently running instances of the application that an individual machine can have
[sr-de] Maximal zulässige, gleichzeitig laufende Instanzen der Anwendung, die ein einzelner Rechner haben kann
.Parameter MaxPerUserInstances
[sr-en] Maximum allowed concurrently running instances of the application that an individual user can have
[sr-de] Maximal zulässige, gleichzeitig laufende Instanzen der Anwendung, die ein einzelner Benutzer haben kann
.Parameter MaxTotalInstances
[sr-en] Maximum allowed total of concurrently running instances of the application in the site
[sr-de] Maximal zulässige Gesamtzahl der gleichzeitig ausgeführten Instanzen der Anwendung in der Site
.Parameter PublishedName
[sr-en] The name seen by end users who have access to this application
[sr-de] Name, der von Endbenutzern gesehen wird, die Zugriff auf diese Anwendung haben
.Parameter ShortcutAddedToDesktop
[sr-en] Specifies whether or not a shortcut to the application should be placed on the user device
[sr-de] Verknüpfung zur Anwendung auf dem Benutzergerät platzieren
.Parameter ShortcutAddedToStartMenu
[sr-en] Specifies whether a shortcut to the application should be placed in the user's start menu on their user device
[sr-de] Verknüpfung zur Anwendung in das Startmenü des Benutzers auf seinem Endgerät legen
.Parameter StartMenuFolder
[sr-en] Name of the start menu folder
.Parameter UserFilterEnabled
[sr-en] Specifies whether the application's user filter is enabled or disabled
[sr-de] Benutzerfilter der Anwendung
.Parameter WaitForPrinterCreation
[sr-en] Specifies whether or not the session waits for the printers to be created before allowing the user to interact with the session
[sr-de] Sitzung wartet darauf, dass die Drucker erstellt werden, bevor der Benutzer mit der Sitzung interagieren kann
.Parameter WorkingDirectory
[sr-en] Specifies which working directory the executable is launched from
[sr-de] Arbeitsverzeichnis der ausführbaren Datei
#>
param(
[Parameter(Mandatory = $true,ParameterSetName = 'ApplicationGroup')]
[Parameter(Mandatory = $true,ParameterSetName = 'DesktopGroup')]
[string]$ApplicationName,
[Parameter(Mandatory = $true,ParameterSetName = 'ApplicationGroup')]
[Parameter(Mandatory = $true,ParameterSetName = 'DesktopGroup')]
[string]$CommandLineExecutable,
[Parameter(Mandatory = $true,ParameterSetName = 'ApplicationGroup')]
[string]$ApplicationGroup,
[Parameter(Mandatory = $true,ParameterSetName = 'DesktopGroup')]
[string]$DesktopGroup,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[ValidateSet('HostedOnDesktop','InstalledOnClient','PublishedContent')]
[string]$ApplicationType,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$CommandLineArguments,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$BrowserName,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$ClientFolder,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[ValidateSet('Low','BelowNormal','Normal','AboveNormal','High')]
[string]$CpuPriorityLevel,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$Description,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$Enabled,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$Visible,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$HomeZoneOnly,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$IconFromClient,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$IgnoreUserHomeZone,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$LocalLaunchDisabled,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[int]$MaxPerMachineInstances,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[int]$MaxPerUserInstancess,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[int]$MaxTotalInstances,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$PublishedName,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$ShortcutAddedToDesktop,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$ShortcutAddedToStartMenu,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$StartMenuFolder,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$UserFilterEnabled,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[bool]$WaitForPrinterCreation,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$WorkingDirectory,
[Parameter(ParameterSetName = 'ApplicationGroup')]
[Parameter(ParameterSetName = 'DesktopGroup')]
[string]$SiteServer
)
$LogID = $null
[bool]$success = $false
try{
[string[]]$Properties = @('Name','PublishedName','Description','Enabled','Visible','UserFilterEnabled')
StartCitrixSessionAdv -ServerName ([ref]$SiteServer)
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'AdminAddress' = $SiteServer
'Name' = $ApplicationName
'CommandLineExecutable' = $CommandLineExecutable
}
[string]$grpType = 'Application group'
[string]$grp
if($PSCmdlet.ParameterSetName -eq 'DesktopGroup'){
$cmdArgs.Add('DesktopGroup',$DesktopGroup)
$grpType = 'Desktop group'
$grp = $DesktopGroup
}
else{
$cmdArgs.Add('ApplicationGroup',$ApplicationGroup)
$grp = $ApplicationGroup
}
if($PSBoundParameters.ContainsKey('CommandLineArguments') -eq $true){
$cmdArgs.Add('CommandLineArguments',$CommandLineArguments)
}
if($PSBoundParameters.ContainsKey('ApplicationType') -eq $true){
$cmdArgs.Add('ApplicationType',$ApplicationType)
}
if($PSBoundParameters.ContainsKey('BrowserName') -eq $true){
$cmdArgs.Add('BrowserName',$BrowserName)
}
if(($ApplicationType -ne 'InstalledOnClient') -and ($PSBoundParameters.ContainsKey('ClientFolder') -eq $true)){
$cmdArgs.Add('ClientFolder',$ClientFolder)
}
if($PSBoundParameters.ContainsKey('CpuPriorityLevel') -eq $true){
$cmdArgs.Add('CpuPriorityLevel',$CpuPriorityLevel)
}
if($PSBoundParameters.ContainsKey('Description') -eq $true){
$cmdArgs.Add('Description',$Description)
}
if($PSBoundParameters.ContainsKey('Enabled') -eq $true){
$cmdArgs.Add('Enabled',$Enabled)
}
if($PSBoundParameters.ContainsKey('Visible') -eq $true){
$cmdArgs.Add('Visible',$Visible)
}
if($PSBoundParameters.ContainsKey('HomeZoneOnly') -eq $true){
$cmdArgs.Add('HomeZoneOnly',$HomeZoneOnly)
}
if($PSBoundParameters.ContainsKey('IconFromClient') -eq $true){
$cmdArgs.Add('IconFromClient',$IconFromClient)
}
if($PSBoundParameters.ContainsKey('IgnoreUserHomeZone') -eq $true){
$cmdArgs.Add('IgnoreUserHomeZone',$IgnoreUserHomeZone)
}
if($PSBoundParameters.ContainsKey('LocalLaunchDisabled') -eq $true){
$cmdArgs.Add('LocalLaunchDisabled',$LocalLaunchDisabled)
}
if($PSBoundParameters.ContainsKey('MaxPerMachineInstances') -eq $true){
$cmdArgs.Add('MaxPerMachineInstances',$MaxPerMachineInstances)
}
if($PSBoundParameters.ContainsKey('MaxPerUserInstances') -eq $true){
$cmdArgs.Add('MaxPerUserInstances',$MaxPerUserInstances)
}
if($PSBoundParameters.ContainsKey('MaxTotalInstances') -eq $true){
$cmdArgs.Add('MaxTotalInstances',$MaxTotalInstances)
}
if($PSBoundParameters.ContainsKey('PublishedName') -eq $true){
$cmdArgs.Add('PublishedName',$PublishedName)
}
if($PSBoundParameters.ContainsKey('ShortcutAddedToDesktop') -eq $true){
$cmdArgs.Add('ShortcutAddedToDesktop',$ShortcutAddedToDesktop)
}
if($PSBoundParameters.ContainsKey('ShortcutAddedToStartMenu') -eq $true){
$cmdArgs.Add('ShortcutAddedToStartMenu',$ShortcutAddedToStartMenu)
}
if($PSBoundParameters.ContainsKey('StartMenuFolder') -eq $true){
$cmdArgs.Add('StartMenuFolder',$StartMenuFolder)
}
if($PSBoundParameters.ContainsKey('UserFilterEnabled') -eq $true){
$cmdArgs.Add('UserFilterEnabled',$UserFilterEnabled)
}
if($PSBoundParameters.ContainsKey('WaitForPrinterCreation') -eq $true){
$cmdArgs.Add('WaitForPrinterCreation',$WaitForPrinterCreation)
}
if($PSBoundParameters.ContainsKey('WorkingDirectory') -eq $true){
$cmdArgs.Add('WorkingDirectory',$WorkingDirectory)
}
StartLogging -ServerAddress $SiteServer -LogText "New Application $($ApplicationName) on $($grpType) $($grp)" -LoggingID ([ref]$LogID)
$cmdArgs.Add('LoggingId',$LogID)
$null = New-BrokerApplication @cmdArgs
$ret = Get-BrokerApplication -Name $ApplicationName -AdminAddress $SiteServer -ErrorAction Stop | Select-Object $Properties
$success = $true
if($SRXEnv) {
$SRXEnv.ResultMessage = $ret
}
else{
Write-Output $ret
}
}
catch{
throw
}
finally{
StopLogging -LoggingID $LogID -ServerAddress $SiteServer -IsSuccessful $success
CloseCitrixSession
}