-
Notifications
You must be signed in to change notification settings - Fork 2
/
Import-CitrixSite.ps1
1231 lines (1179 loc) · 56.3 KB
/
Import-CitrixSite.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.Synopsis
Import the configuration from XML file
.Description
Import the configuration from a specified XML file to Citrix Site.
Icons encoded data are imported from a "resources" folder set as a parameter.
Created element are:
- Site Properties (Trust XML, Tags)
- Administrators (ADGroup/ADUser, scopes, roles)
- Catalogs (including Provisioning Schemes and Identity Pools)
- Delivery Groups (including Power Management rules and Reboot Schedules)
- Published Applications (including icons and File Type Associations)
If a resource (administrators, catalogs, applications and so on) with the same name already exists,
the script won't altered the existing one.
and will display a warning.
.Parameter XMLFile
XML File to import configuration from.
Must be generated from Export-CitrixSite.ps1 (it can be modified afterwards
but the structure must match one from the previous powershell script).
.Parameter ResourcesFolder
Specifiy the folder where are stored Icon encoded data for published applications.
efault, it will create a file in the current directory.
.Example
# Import the configuration from export.xml file
Import-CitrixSite.ps1 -XMLFile "./export.xml"
.Example
# Connect to "CTXDDC01" to import the configuration from export.xml file
Import-CitrixSite.ps1 -DeliveryController "CTXDDC01" -XMLFile "./export.xml"
.Example
# Import the configuration from export.xml file and use "resources" directory to import icon
# encoded data
Import-CitrixSite.ps1 -XMLFile "./export.xml" -resourcesfolder "./resources"
.Example
# Import the configuration from export.xml file and log the output in C:\Temp\test.log
Import-CitrixSite.ps1 -XMLFile "./export.xml" -Log "C:\temp\test.log"
.Example
# Provision 10 VMs to the "Windows 10" catalog and assign them to the "Desktop" delivery group.
VDI_Provisionning.ps1 -VDICount 10 -Catalog "Windows10" -DeliveryGroup "Desktop"
#>
[CmdletBinding()]
Param(
# Declaring input variables for the script
[Parameter(Mandatory=$true)] [string]$XMLFile,
[Parameter(Mandatory=$false)] [string]$ResourcesFolder,
[Parameter(Mandatory=$false)] [string]$DeliveryController,
[Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()] [string]$LogFile=".\Import-CitrixSite.log"
)
#Start logging
Start-Transcript -Path $LogFile
#Setting variables prior to their usage is not mandatory
Set-StrictMode -Version 2
#Check Snapin can be loaded
#Could be improved by only loading the necessary modules but it would not be compatible with version older than 1912
Write-Host "Loading Citrix Snapin... " -NoNewline
if(!(Add-PSSnapin Citrix* -ErrorAction SilentlyContinue -PassThru )){
Write-Host "Failed" -ForegroundColor Red
Write-Host "Citrix Snapin cannot be loaded. Please, check the component is installed on the computer." -ForegroundColor Red
#Stop logging
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
################################################################################################
#Checking the parameters
################################################################################################
#Check if the DeliveryController parameter is set or if it has to use the local machine
if($DeliveryController){
#Check if the parameter is a FQDN or not
Write-Host "Trying to contact the Delivery Controller $DeliveryController... " -NoNewline
if($DeliveryController -contains "."){
$DDC = Get-BrokerController -DNSName "$DeliveryController"
} else {
$DDC = Get-BrokerController -DNSName "$DeliveryController.$env:USERDNSDOMAIN"
}
} else {
Write-Host "Trying to contact the Delivery Controller $env:COMPUTERNAME... " -NoNewline
$DDC = Get-BrokerController -DNSName "$env:COMPUTERNAME.$env:USERDNSDOMAIN"
}
if(($DDC)){
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host "Failed" -ForegroundColor Red
Write-Host "Cannot contact the Delivery Controller. Please, check the role is installed on the target computer and your account is allowed to communicate with it." -ForegroundColor Red
}
#TODO Check if current DDC = DDC in the XML
#WARN about lauching the script on the same DDC as the one in export file!
#Check if export file exists
Write-Host "Checking XML file... " -NoNewline
Try{
#TODO improve check (google to check XML)
$xdoc = New-Object System.Xml.XmlDocument
$file = Resolve-Path($XMLFile)
$xdoc.load($file)
}
catch{
Write-Host "An error occured while importing XML file" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
#Check if resources folder exists (to import icon)
Write-Host "Checking resources folder... " -NoNewline
#TODO improve check (uid.txt as childitem)
if(Test-Path -path $ResourcesFolder){
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host "An error occured while checking resources folder. Ensure the path is correct." -ForegroundColor Red
Stop-Transcript
break
}
################################################################################################
#Setting Site's Properties
################################################################################################
if($xdoc.site.Properties.TrustXML.InnerText){
Write-Host "Setting Site's TrustXML Property... " -NoNewline
try {
$value = [bool]$xdoc.site.Properties.TrustXML.InnerText
Set-BrokerSite -TrustRequestsSentToTheXmlServicePort $value
}
catch {
Write-Host "An error occured while setting Site's TrustXML Property" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
}
################################################################################################
#Setting Site's Tags
################################################################################################
Write-Host "Setting Site's Tags... " -NoNewline
if($xdoc.site.tags){
$tags = $xdoc.site.tags.tag
foreach($tag in $tags){
if(!(Get-BrokerTag -Name $tag.Name -errorAction SilentlyContinue)){
Write-host "Adding new tag" $tag.Name"... " -NoNewline
try {
New-BrokerTag -Name $scope.Name | out-null
Write-Host "OK" -ForegroundColor Green
}
catch {
Write-Host "An error occured while adding a new tag" -ForegroundColor Red
Stop-Transcript
break
}
} else {
Write-Host $tag.Name "already exists. tag won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually tag's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No tags to import" -ForegroundColor Yellow
}
################################################################################################
#Setting Site's Administrators
################################################################################################
Write-Host "Setting Roles config... "
if($xdoc.site.Roles){
$roles = $xdoc.site.roles.role
foreach($role in $roles){
if(!(Get-AdminRole -Name $role.Name -errorAction SilentlyContinue)){
Write-host "Adding new role" $role.Name"... " -NoNewline
try {
New-AdminRole -Name $role.Name -description $role.description | out-null
Write-Host "OK" -ForegroundColor Green
Write-host "Adding permissions to" $role.name"... " -NoNewline
try {
Add-AdminPermission -Role $role.name -Permission $role.permission
Write-host "OK" -ForegroundColor Green
}
catch {
Write-Host "An error occured while setting permissions for" $role.name -ForegroundColor Red
Stop-Transcript
break
}
}
catch {
Write-Host "An error occured while adding a new role" -ForegroundColor Red
Stop-Transcript
break
}
} else {
Write-Host $role.name "already exists. Role won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually role's properties." -ForegroundColor Yellow
}
}
}else {
Write-Host "No roles to import" -ForegroundColor Yellow
}
Write-Host "Setting Scopes config... "
if($xdoc.site.scopes){
$scopes = $xdoc.site.scopes.scope
foreach($scope in $scopes){
if(!(Get-AdminScope -Name $scope.Name -errorAction SilentlyContinue)){
Write-host "Adding new scope" $scope.Name"... " -NoNewline
try {
New-AdminScope -Name $scope.Name -description $scope.description | out-null
Write-Host "OK" -ForegroundColor Green
}
catch {
Write-Host "An error occured while adding a new scope" -ForegroundColor Red
Stop-Transcript
break
}
} else {
Write-Host $scope.Name "already exists. Scope won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually scope's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No scopes to import" -ForegroundColor Yellow
}
Write-Host "Setting Administrators config... "
if($xdoc.site.administrators){
$administrators = $xdoc.site.administrators.administrator
foreach($administrator in $administrators){
if(!(get-adminadministrator -Name $administrator.name -errorAction SilentlyContinue)){
Write-host "Adding new admin" $administrator.Name"... " -NoNewline
try {
New-AdminAdministrator -Name $administrator.Name | Out-Null
Write-Host "OK" -ForegroundColor Green
Write-host "Setting permissions to" $administrator.name"... " -NoNewline
try {
Add-AdminRight -Role $administrator.rolename -Scope $administrator.scopeName -Administrator $administrator.name
Write-host "OK" -ForegroundColor Green
}
catch {
Write-Host "An error occured while setting permissions for" $administrator.name -ForegroundColor Red
Stop-Transcript
break
}
}
catch {
Write-Host "An error occured while adding a new administrator" -ForegroundColor Red
Stop-Transcript
break
}
} else {
Write-Host $administrator.Name "already exists. Administrator won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually administrator's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No administrators to import" -ForegroundColor Yellow
}
################################################################################################
#Setting AcctIdentityPool
################################################################################################
Write-Host "Setting AcctIdentityPool config... "
if($xdoc.site.AcctIdentityPools){
$AcctIdentityPools = $xdoc.site.AcctIdentityPools.AcctIdentityPool
foreach($AcctIdentityPool in $AcctIdentityPools){
if(!(get-AcctIdentityPool -IdentityPoolName $AcctIdentityPool.IdentityPoolName -errorAction SilentlyContinue)){
Write-host "Adding new AcctIdentityPool" $AcctIdentityPool.IdentityPoolName"... " -NoNewline
$Command = "New-AcctIdentityPool -IdentityPoolName """ + $AcctIdentityPool.IdentityPoolName + """"
$command += " -NamingScheme """ + $AcctIdentityPool.NamingScheme + """"
$command += " -NamingSchemeType """ + $AcctIdentityPool.NamingSchemeType + """"
$command += " -OU """+ $AcctIdentityPool.OU + """"
$command += " -Domain """+ $AcctIdentityPool.Domain + """"
try {
$count = $AcctIdentityPool.scope.count
$i=0
$command += " -Scope """
while ($i -lt $count) {
$command += $AcctIdentityPool.scope[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one scope is declared
$command += " -Scope """ + $provscheme.scope + """"
}
catch {
#No Scope to assign
}
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new IdentityPoolName" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $AcctIdentityPool.IdentityPoolName "already exists. IdentityPoolName won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually IdentityPoolName's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No AcctIdentityPools to import" -ForegroundColor Yellow
}
################################################################################################
#Setting ProvSchemes
################################################################################################
Write-Host "Setting ProvSchemes config... "
if($xdoc.site.provschemes){
$provschemes = $xdoc.site.provschemes.provscheme
foreach($provscheme in $provschemes){
if(!(get-ProvScheme -ProvisioningSchemeName $provscheme.ProvisioningSchemeName -errorAction SilentlyContinue)){
Write-host "Adding new ProvScheme" $provscheme.ProvisioningSchemeName"... " -NoNewline
$command = "New-ProvScheme -ProvisioningSchemeName """ + $provscheme.ProvisioningSchemeName + """"
$command += " -HostingUnitName """ + $provscheme.HostingUnitName + """"
$command += " -IdentityPoolName """ + $provscheme.IdentityPoolName + """"
if($provscheme.CleanOnBoot){
$command += " -CleanOnBoot"
}
$command += " -MasterImageVM """ + $provscheme.MasterImageVM + """"
$command += " -VMCpuCount """ + $provscheme.CpuCount + """"
$command += " -VMMemoryMB """ + $provscheme.MemoryMB + """"
if($provscheme.UsePersonalVDiskStorage -match "True"){ #it is not a boolean but a string
$command += " -UsePersonalVDiskStorage"
#Require PersonalVDiskDriveLetter parameter
}
if($ProvScheme.UseWriteBackCache -match "True"){ #it is not a boolean but a string
$command += " -UseWriteBackCache"
$command += " -WriteBackCacheDiskSize """ + $provscheme.WriteBackCacheDiskSize + """"
$command += " -WriteBackCacheMemorySize """ + $provscheme.WriteBackCacheMemorySize + """"
}
try {
$count = $provscheme.scope.count
$i=0
$command += " -Scope """
while ($i -lt $count) {
$command += $provscheme.scope[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one scope is declared
$command += " -Scope """ + $provscheme.scope + """"
}
catch {
#No Scope to assign
}
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new ProvSchemes" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $provscheme.ProvisioningSchemeName "already exists. ProvScheme won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually ProvScheme's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No ProvSchemes to import" -ForegroundColor Yellow
}
################################################################################################
#Setting Catalogs
################################################################################################
Write-Host "Setting Catalogs config... "
if($xdoc.site.Catalogs){
$Catalogs = $xdoc.site.Catalogs.Catalog
foreach($Catalog in $Catalogs){
if(!(Get-BrokerCatalog -Name $Catalog.Name -errorAction SilentlyContinue)){
Write-host "Adding new Catalog" $Catalog.Name"... " -NoNewline
$command = "New-BrokerCatalog -Name """ + $Catalog.Name + """"
$command += " -AllocationType """ + $Catalog.AllocationType + """"
$command += " -Description """ + $Catalog.Description + """"
$command += " -ProvisioningType """ + $Catalog.ProvisioningType + """"
$command += " -SessionSupport """ + $Catalog.SessionSupport + """"
$command += " -PersistUserChanges """ + $Catalog.PersistUserChanges + """"
if($Catalog.IsRemotePC -match "True"){
$command += " -IsRemotePC `$True"
}
if($Catalog.IsRemotePC -match "False"){
$command += " -IsRemotePC `$False"
}
if($Catalog.MachinesArePhysical -match "True"){
$command += " -MachinesArePhysical `$True"
}
if($Catalog.MachinesArePhysical -match "False"){
$command += " -MachinesArePhysical `$False"
}
if($Catalog.ProvisioningSchemeName){
$ProvisioningSchemeUid = (Get-ProvScheme -ProvisioningSchemeName $Catalog.ProvisioningSchemeName).ProvisioningSchemeUid
$command += " -ProvisioningSchemeId """ + $ProvisioningSchemeUid + """"
}
try {
$count = $Catalog.scope.count
$i=0
$command += " -Scope """
while ($i -lt $count) {
$command += $Catalog.scope[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one scope is declared
$command += " -Scope """ + $Catalog.scope + """"
}
catch {
#No Scope to assign
}
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new Catalog" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $Catalog.Name "already exists. Catalog won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually Catalog's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No Catalogs to import" -ForegroundColor Yellow
}
################################################################################################
#Setting DesktopGroups
################################################################################################
Write-Host "Setting DesktopGroups config... "
if($xdoc.site.DeliveryGroups){
$DesktopGroups = $xdoc.site.DeliveryGroups.DeliveryGroup
foreach($DesktopGroup in $DesktopGroups){
if(!(Get-BrokerDesktopGroup -Name $DesktopGroup.Name -errorAction SilentlyContinue)){
Write-host "Adding new DesktopGroup" $DesktopGroup.Name"... " -NoNewline
$command = "New-BrokerDesktopGroup -Name """ + $DesktopGroup.Name + """"
$command += " -PublishedName """ + $DesktopGroup.PublishedName + """"
$command += " -Description """ + $DesktopGroup.Description + """"
$command += " -DesktopKind """ + $DesktopGroup.DesktopKind + """"
$command += " -SessionSupport """ + $DesktopGroup.SessionSupport + """"
if($DesktopGroup.ShutdownDesktopsAfterUse -match "True"){
$command += " -ShutdownDesktopsAfterUse `$True"
}
if($DesktopGroup.ShutdownDesktopsAfterUse -match "False"){
$command += " -ShutdownDesktopsAfterUse `$False"
}
if($DesktopGroup.AutomaticPowerOnForAssigned -match "True"){
$command += " -AutomaticPowerOnForAssigned `$True"
}
if($DesktopGroup.AutomaticPowerOnForAssigned -match "False"){
$command += " -AutomaticPowerOnForAssigned `$False"
}
if($DesktopGroup.AutomaticPowerOnForAssignedDuringPeak -match "True"){
$command += " -AutomaticPowerOnForAssignedDuringPeak `$True"
}
if($DesktopGroup.AutomaticPowerOnForAssignedDuringPeak -match "False"){
$command += " -AutomaticPowerOnForAssignedDuringPeak `$False"
}
$command += " -DeliveryType """ + $DesktopGroup.DeliveryType + """"
if($DesktopGroup.Enabled -match "True"){
$command += " -Enabled `$True"
}
if($DesktopGroup.Enabled -match "False"){
$command += " -Enabled `$False"
}
$iconUid = $DesktopGroup.IconUid
if(test-path -Path "./resources/$iconuid.txt"){
$encodedData = Get-Content -Path "./resources/$iconuid.txt"
$brokericon = New-BrokerIcon -EncodedIconData $encodedData
$command += " -IconUid """ + $brokericon.Uid + """"
}
if($DesktopGroup.IsRemotePC -match "True"){
$command += " -IsRemotePC `$True"
}
if($DesktopGroup.IsRemotePC -match "False"){
$command += " -IsRemotePC `$False"
}
$command += " -OffPeakBufferSizePercent """ + $DesktopGroup.OffPeakBufferSizePercent + """"
$command += " -OffPeakDisconnectAction """ + $DesktopGroup.OffPeakDisconnectAction + """"
$command += " -OffPeakDisconnectTimeout """ + $DesktopGroup.OffPeakDisconnectTimeout + """"
$command += " -OffPeakExtendedDisconnectAction """ + $DesktopGroup.OffPeakExtendedDisconnectAction + """"
$command += " -OffPeakExtendedDisconnectTimeout """ + $DesktopGroup.OffPeakExtendedDisconnectTimeout + """"
$command += " -OffPeakLogOffAction """ + $DesktopGroup.OffPeakLogOffAction + """"
$command += " -OffPeakLogOffTimeout """ + $DesktopGroup.OffPeakLogOffTimeout + """"
$command += " -PeakBufferSizePercent """ + $DesktopGroup.PeakBufferSizePercent + """"
$command += " -PeakDisconnectAction """ + $DesktopGroup.PeakDisconnectAction + """"
$command += " -PeakDisconnectTimeout """ + $DesktopGroup.PeakDisconnectTimeout + """"
$command += " -PeakExtendedDisconnectAction """ + $DesktopGroup.PeakExtendedDisconnectAction + """"
$command += " -PeakExtendedDisconnectTimeout """ + $DesktopGroup.PeakExtendedDisconnectTimeout + """"
$command += " -PeakLogOffAction """ + $DesktopGroup.PeakLogOffAction + """"
$command += " -PeakLogOffTimeout """ + $DesktopGroup.PeakLogOffTimeout + """"
try {
$count = $DesktopGroup.scope.count
$i=0
$command += " -Scope """
while ($i -lt $count) {
$command += $DesktopGroup.scope[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one scope is declared
$command += " -Scope """ + $DesktopGroup.scope + """"
}
catch {
#No Scope to assign
}
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new DesktopGroup" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $DesktopGroup.Name "already exists. DesktopGroup won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually DesktopGroup's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No DesktopGroups to import" -ForegroundColor Yellow
}
################################################################################################
#Setting EntitlementPolicyRules
################################################################################################
Write-Host "Setting EntitlementPolicyRules config... "
if($xdoc.site.EntitlementPolicyRules){
$EntitlementPolicyRules = $xdoc.site.EntitlementPolicyRules.EntitlementPolicyRule
foreach($EntitlementPolicyRule in $EntitlementPolicyRules){
if(!(Get-BrokerEntitlementPolicyRule -Name $EntitlementPolicyRule.Name -errorAction SilentlyContinue)){
Write-host "Adding new EntitlementPolicyRule" $EntitlementPolicyRule.Name"... " -NoNewline
$command = "New-BrokerEntitlementPolicyRule -Name """ + $EntitlementPolicyRule.Name + """"
$DesktopGroupUid = (Get-BrokerDesktopGroup -Name $EntitlementPolicyRule.DesktopGroupName).Uid
$command += " -DesktopGroupUid """ + $DesktopGroupUid + """"
$command += " -Description """ + $EntitlementPolicyRule.Description + """"
$command += " -PublishedName """ + $EntitlementPolicyRule.PublishedName + """"
if($EntitlementPolicyRule.ExcludedUserFilterEnabled -match "True"){
$command += " -ExcludedUserFilterEnabled `$True"
try {
$count = $EntitlementPolicyRule.ExcludedUser.count
$i=0
$command += " -ExcludedUsers """
while ($i -lt $count) {
$command += $EntitlementPolicyRule.ExcludedUser[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one ExcludedUsers is declared
$command += " -ExcludedUsers """ + $EntitlementPolicyRule.ExcludedUser + """"
}
catch {
#No ExcludedUsers to assign
}
}
}
if($EntitlementPolicyRule.ExcludedUserFilterEnabled -match "False"){
$command += " -ExcludedUserFilterEnabled `$False"
}
if($EntitlementPolicyRule.IncludedUserFilterEnabled -match "True"){
$command += " -IncludedUserFilterEnabled `$True"
try {
$count = $EntitlementPolicyRule.IncludedUser.count
$i=0
$command += " -IncludedUsers """
while ($i -lt $count) {
$command += $EntitlementPolicyRule.IncludedUser[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one IncludedUsers is declared
$command += " -IncludedUsers """ + $EntitlementPolicyRule.IncludedUser + """"
}
catch {
#No IncludedUsers to assign
}
}
}
if($EntitlementPolicyRule.IncludedUserFilterEnabled -match "False"){
$command += " -IncludedUserFilterEnabled `$False"
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new EntitlementPolicyRule" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $EntitlementPolicyRule.Name "already exists. EntitlementPolicyRule won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually EntitlementPolicyRule's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No EntitlementPolicyRules to import" -ForegroundColor Yellow
}
################################################################################################
#Setting BrokerAppEntitlementPolicyRules
################################################################################################
Write-Host "Setting BrokerAppEntitlementPolicyRules config... "
if($xdoc.site.BrokerAppEntitlementPolicyRules){
$BrokerAppEntitlementPolicyRules = $xdoc.site.BrokerAppEntitlementPolicyRules.BrokerAppEntitlementPolicyRule
foreach($BrokerAppEntitlementPolicyRule in $BrokerAppEntitlementPolicyRules){
if(!(Get-BrokerAppEntitlementPolicyRule -Name $BrokerAppEntitlementPolicyRule.Name -errorAction SilentlyContinue)){
Write-host "Adding new BrokerAppEntitlementPolicyRule" $BrokerAppEntitlementPolicyRule.Name"... " -NoNewline
$command = "New-BrokerAppEntitlementPolicyRule -Name """ + $BrokerAppEntitlementPolicyRule.Name + """"
$DesktopGroupUid = (Get-BrokerDesktopGroup -Name $BrokerAppEntitlementPolicyRule.DesktopGroupName).Uid
$command += " -DesktopGroupUid """ + $DesktopGroupUid + """"
$command += " -Description """ + $BrokerAppEntitlementPolicyRule.Description + """"
if($BrokerAppEntitlementPolicyRule.Enabled -match "False"){
$command += " -Enabled `$False"
}
if($BrokerAppEntitlementPolicyRule.Enabled -match "True"){
$command += " -Enabled `$True"
}
if($BrokerAppEntitlementPolicyRule.LeasingBehavior -match "False"){
$command += " -LeasingBehavior `$False"
}
if($BrokerAppEntitlementPolicyRule.LeasingBehavior -match "True"){
$command += " -LeasingBehavior `$True"
}
if($BrokerAppEntitlementPolicyRule.SessionReconnection -match "False"){
$command += " -SessionReconnection `$False"
}
if($BrokerAppEntitlementPolicyRule.SessionReconnection -match "True"){
$command += " -SessionReconnection `$True"
}
if($BrokerAppEntitlementPolicyRule.ExcludedUserFilterEnable -match "False"){
$command += " -ExcludedUserFilterEnable `$False"
}
if($BrokerAppEntitlementPolicyRule.ExcludedUserFilterEnable -match "True"){
$command += " -ExcludedUserFilterEnable `$True"
}
if($BrokerAppEntitlementPolicyRule.IncludedUserFilterEnable -match "False"){
$command += " -IncludedUserFilterEnable `$False"
}
if($BrokerAppEntitlementPolicyRule.IncludedUserFilterEnable -match "True"){
$command += " -IncludedUserFilterEnable `$True"
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new BrokerAppEntitlementPolicyRule" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $BrokerAppEntitlementPolicyRule.Name "already exists. BrokerAppEntitlementPolicyRule won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually BrokerAppEntitlementPolicyRule's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No BrokerAppEntitlementPolicyRules to import" -ForegroundColor Yellow
}
################################################################################################
#Setting Brokerpowertimeschemes
################################################################################################
Write-Host "Setting Brokerpowertimeschemes config... "
if($xdoc.site.Brokerpowertimeschemes){
$Brokerpowertimeschemes = $xdoc.site.Brokerpowertimeschemes.Brokerpowertimescheme
foreach($Brokerpowertimescheme in $Brokerpowertimeschemes){
if(!(Get-Brokerpowertimescheme -Name $Brokerpowertimescheme.Name -errorAction SilentlyContinue)){
Write-host "Adding new Brokerpowertimescheme" $Brokerpowertimescheme.Name"... " -NoNewline
$command = "New-Brokerpowertimescheme -Name """ + $Brokerpowertimescheme.Name + """"
$DesktopGroupUid = (Get-BrokerDesktopGroup -Name $Brokerpowertimescheme.DesktopGroupName).Uid
$command += " -DesktopGroupUid """ + $DesktopGroupUid + """"
$command += " -DaysOfWeek """ + $Brokerpowertimescheme.DaysOfWeek + """"
$command += " -DisplayName """ + $Brokerpowertimescheme.DisplayName + """"
if($Brokerpowertimescheme.PoolUsingPercentage -match "True"){
$command += " -PoolUsingPercentage `$True"
}
if($Brokerpowertimescheme.PoolUsingPercentage -match "False"){
$command += " -PoolUsingPercentage `$False"
}
$count = $Brokerpowertimescheme.PeakHour.count
$i=0
$command += " -PeakHours @("
while ($i -lt $count) {
if($Brokerpowertimescheme.PeakHour[$i] -match "True"){
$command += "`$True"
}
if($Brokerpowertimescheme.PeakHour[$i] -match "False"){
$command += "`$False"
}
if($i -ne ($count - 1)){
$command += ","
} else {
$command += ")"
}
$i++
}
$count = $Brokerpowertimescheme.PoolSize.count
$i=0
$command += " -PoolSize @("
while ($i -lt $count) {
$command += $Brokerpowertimescheme.PoolSize[$i]
if($i -ne ($count - 1)){
$command += ","
} else {
$command += ")"
}
$i++
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new Brokerpowertimescheme" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $Brokerpowertimescheme.Name "already exists. Brokerpowertimescheme won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually Brokerpowertimescheme's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No Brokerpowertimeschemes to import" -ForegroundColor Yellow
}
################################################################################################
#Setting BrokeraccesspolicyRules
################################################################################################
Write-Host "Setting BrokeraccesspolicyRules config... "
if($xdoc.site.BrokeraccesspolicyRules){
$BrokeraccesspolicyRules = $xdoc.site.BrokeraccesspolicyRules.BrokeraccesspolicyRule
foreach($BrokeraccesspolicyRule in $BrokeraccesspolicyRules){
if(!(Get-BrokeraccesspolicyRule -Name $BrokeraccesspolicyRule.Name -errorAction SilentlyContinue)){
Write-host "Adding new BrokeraccesspolicyRule" $BrokeraccesspolicyRule.Name"... " -NoNewline
$command = "New-BrokeraccesspolicyRule -Name """ + $BrokeraccesspolicyRule.Name + """"
$DesktopGroupUid = (Get-BrokerDesktopGroup -Name $BrokeraccesspolicyRule.DesktopGroupName).Uid
$command += " -DesktopGroupUid """ + $DesktopGroupUid + """"
$command += " -AllowedConnections """ + $BrokeraccesspolicyRule.AllowedConnections + """"
$command += " -AllowedProtocols @(""" + $BrokeraccesspolicyRule.AllowedProtocols.Replace(" ",""",""") + """)"
$command += " -AllowedUsers """ + $BrokeraccesspolicyRule.AllowedUsers + """"
$command += " -Description """ + $BrokeraccesspolicyRule.Description + """"
if($BrokeraccesspolicyRule.AllowRestart -match "True"){
$command += " -AllowRestart `$True"
}
if($BrokeraccesspolicyRule.AllowRestart -match "False"){
$command += " -AllowRestart `$False"
}
if($BrokeraccesspolicyRule.IncludedSmartAccessFilterEnabled -match "True"){
$command += " -IncludedSmartAccessFilterEnabled `$True"
}
if($BrokeraccesspolicyRule.IncludedSmartAccessFilterEnabled -match "False"){
$command += " -IncludedSmartAccessFilterEnabled `$False"
}
if($BrokeraccesspolicyRule.Enabled -match "True"){
$command += " -Enabled `$True"
}
if($BrokeraccesspolicyRule.Enabled -match "False"){
$command += " -Enabled `$False"
}
if($BrokeraccesspolicyRule.IncludedUserFilterEnabled -match "True"){
$command += " -IncludedUserFilterEnabled `$True"
}
if($BrokeraccesspolicyRule.IncludedUserFilterEnabled -match "False"){
$command += " -IncludedUserFilterEnabled `$False"
}
try {
$count = $BrokeraccesspolicyRule.IncludedUser.count
$i=0
$command += " -IncludedUsers """
while ($i -lt $count) {
$command += $BrokeraccesspolicyRule.IncludedUser[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one IncludedUsers is declared
$command += " -IncludedUsers """ + $BrokeraccesspolicyRule.IncludedUser + """"
}
catch {
#No IncludedUsers to assign
}
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new BrokeraccesspolicyRule" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $BrokeraccesspolicyRule.Name "already exists. BrokeraccesspolicyRule won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually BrokeraccesspolicyRule's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No BrokeraccesspolicyRules to import" -ForegroundColor Yellow
}
################################################################################################
#Setting Brokerrebootschedules
################################################################################################
Write-Host "Setting Brokerrebootschedules config... "
if($xdoc.site.Brokerrebootschedules){
$Brokerrebootschedules = $xdoc.site.Brokerrebootschedules.Brokerrebootschedule
foreach($Brokerrebootschedule in $Brokerrebootschedules){
if(!(Get-BrokerrebootscheduleV2 -Name $Brokerrebootschedule.Name -errorAction SilentlyContinue)){
Write-host "Adding new Brokerrebootschedule" $Brokerrebootschedule.Name"... " -NoNewline
$command = "New-BrokerrebootscheduleV2 -Name """ + $Brokerrebootschedule.Name + """"
$DesktopGroupUid = (Get-BrokerDesktopGroup -Name $Brokerrebootschedule.DesktopGroupName).Uid
$command += " -DesktopGroupUid """ + $DesktopGroupUid + """"
$command += " -RebootDuration """ + $Brokerrebootschedule.RebootDuration + """"
$command += " -Description """ + $Brokerrebootschedule.Description + """"
$command += " -Frequency """ + $Brokerrebootschedule.Frequency + """"
if($Brokerrebootschedule.Frequency -notmatch "Daily"){
$command += " -Day """ + $Brokerrebootschedule.Day + """"
}
$command += " -StartTime """ + $Brokerrebootschedule.StartTime + """"
$command += " -WarningDuration """ + $Brokerrebootschedule.WarningDuration + """"
$command += " -WarningMessage """ + $Brokerrebootschedule.WarningMessage + """"
$command += " -WarningRepeatInterval """ + $Brokerrebootschedule.WarningRepeatInterval + """"
$command += " -WarningTitle """ + $Brokerrebootschedule.WarningTitle + """"
if($Brokerrebootschedule.Enabled -match "True"){
$command += " -Enabled `$True"
}
if($Brokerrebootschedule.Enabled -match "False"){
$command += " -Enabled `$False"
}
#write-host $command
#Pause
try {
Invoke-Expression $command | Out-Null
}
catch {
Write-Host "An error occured while adding a new Brokerrebootschedule" -ForegroundColor Red
Stop-Transcript
break
}
Write-Host "OK" -ForegroundColor Green
} else {
Write-Host $Brokerrebootschedule.Name "already exists. Brokerrebootschedule won't be modified by this script." -ForegroundColor Yellow
Write-Host "Check manually Brokerrebootschedule's properties." -ForegroundColor Yellow
}
}
} else {
Write-Host "No Brokerrebootschedules to import" -ForegroundColor Yellow
}
################################################################################################
#Setting Application Groups
################################################################################################
Write-Host "Setting Application Groups config... "
if($xdoc.site.ApplicationGroups){
$ApplicationGroups = $xdoc.site.ApplicationGroups.ApplicationGroup
foreach($ApplicationGroup in $ApplicationGroups){
if(!(Get-BrokerapplicationGroup -Name $ApplicationGroup.Name -errorAction SilentlyContinue)){
Write-host "Adding new Application Group" $ApplicationGroup.Name"... " -NoNewline
$command = "New-BrokerapplicationGroup -Name """ + $ApplicationGroup.Name + """"
if($ApplicationGroup.AdminFolderName -ne ""){
$command += " -AdminFolder """ + $ApplicationGroup.AdminFolderName + """"
}
$command += " -Description """ + $ApplicationGroup.Description + """"
if($ApplicationGroup.Enabled -match "True"){
$command += " -Enabled `$True"
}
if($ApplicationGroup.Enabled -match "False"){
$command += " -Enabled `$False"
}
if($ApplicationGroup.SessionSharingEnabled -match "True"){
$command += " -SessionSharingEnabled `$True"
}
if($ApplicationGroup.SessionSharingEnabled -match "False"){
$command += " -SessionSharingEnabled `$False"
}
if($ApplicationGroup.SingleAppPerSession -match "True"){
$command += " -SingleAppPerSession `$True"
}
if($ApplicationGroup.SingleAppPerSession -match "False"){
$command += " -SingleAppPerSession `$False"
}
if($ApplicationGroup.UserFilterEnabled -match "True"){
$command += " -UserFilterEnabled `$True"
}
if($ApplicationGroup.UserFilterEnabled -match "False"){
$command += " -UserFilterEnabled `$False"
}
try {
$count = $ApplicationGroup.RestrictToTag.count
$i=0
$command += " -RestrictToTag """
while ($i -lt $count) {
$command += $ApplicationGroup.RestrictToTag[$i]
if($i -ne ($count - 1)){
$command += ""","""
} else {
$command += """"
}
$i++
}
}
catch {
try { #Only one IncludedUsers is declared
$command += " -RestrictToTag """ + $ApplicationGroup.RestrictToTag + """"
}
catch {
#No IncludedUsers to assign
}
}
try {