-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCitrixAdminTool.ps1
4013 lines (2947 loc) · 200 KB
/
CitrixAdminTool.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
#####################################################################
# Citrix Admin Tool #
# Developped by : Brian L. Kruse #
# #
# Date: 24-11-2020 #
# Last Update: 03-05-2024 #
# #
# Version: 2.0 #
# #
# Purpose: A quick visual way to get Citrix related Information #
# #
# #
# #
# #
#####################################################################
#region Debug variable
$debug = $false
#endregion Debug variable
#region SnapIns to be loaded
## Cloud sync on prem authentication
<#
$snapinLicV1 = "Citrix.Licensing.Admin.V1"
$snapinAddedLicV1 = Get-PSSnapin | Select-String $snapinLicV1
if (!$snapinAddedLicV1)
{
Add-PSSnapin $snapinLicV1
}
#>
$snapinNameC = "citrix*"
$snapinAdded = Get-PSSnapin | Select-String $snapinNameC
if (!$snapinAdded)
{
Add-PSSnapin $snapinNameC
}
$snapinNameA = "Citrix.*.Admin.V*"
$snapinAdded = Get-PSSnapin | Select-String $snapinNameA
if (!$snapinAdded)
{
Add-PSSnapin $snapinNameA
}
$snapinNameAV3 = "Citrix.ADIdentity.Admin.V2"
$snapinAdded = Get-PSSnapin | Select-String $snapinNameAV3
if (!$snapinAdded)
{
Add-PSSnapin $snapinNameAV3
}
$snapinNameAV = "Citrix.\*.Admin.V\*"
$snapinAdded = Get-PSSnapin | Select-String $snapinNameAV
if (!$snapinAdded)
{
Add-PSSnapin $snapinNameAV
}
$snapinNameB = "Citrix.Broker.Admin.v2"
$snapinAdded = Get-PSSnapin | Select-String $snapinNameB
if (!$snapinAdded)
{
Add-PSSnapin $snapinNameB
}
# Authentication OnPrem validation to avoid Cloud authentication - outline the "Set-XDCredentials -ProfileType onPrem" if connecting to Citrix Cloud
Set-XDCredentials -ProfileType onPrem
#Get-XDAuthentication
#endregion SnapIns to be loaded
#################################################### Functions #######################################################
# Default Global Variables
#region Default variable settings
# Insert the Delivery Controller like - "DDC1.domain.ext","DDC2.domain.etx"
$DDC = "ddc1.contoso.net"
# Insert Domain like - "domain.ext"
$Domain = "contoso.net"
# Insert XenServer hostname for the Virtual Desktops like - "xenserver1.domain.ext"
$XenServerVDI = "xenserver1.contoso.net"
# Insert eihter all AD Groups like - "VirtualDesktop-Group1", " VirtualDesktop-Group2" or enter e prefix to import all AD Groups accessing Virtual Desktops like "*DesktopGroup*"
$groups = (Get-ADGroup -Filter {name -like "CVAD-AD-Group*"} -Properties Name | Select Name | Select-Object @{l="Name";e={$_.Name -join " "}}).Name | Sort
# if more different prefix - Insert eihter all AD Groups like - "VirtualDesktop-Group1", " VirtualDesktop-Group2" or enter e prefix to import all AD Groups accessing Virtual Desktops like "*DesktopGroup*"
$groupsTIER2 = (Get-ADGroup -Filter {name -like "CVAD-AD-Group*"} -Properties Name | Select Name | Select-Object @{l="Name";e={$_.Name -join " "}}).Name | Sort
# For trimming the domain name for some functions like "domain\\"
$DomainTrim = "CONTOSO\\"
# Virtual Machine prefix if needed like "*prefix*"
$VDIPrefix = "*CVADVDI*"
# Virtual Machine prefix if needed like "*prefix*"
$XenAppPrefix = "*CVADXA*"
# Domain PreFix without extension like - "Domain\"
$DomainPrefix = "CONTOSO\"
# Specific VDIUser for delete, maintenance etc
$specificUser = $DomainPrefix + "INITIALS"
#endregion Default variable settings
############################################## VDI Check user assignment Function ####################################
function VDIAssign{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIAssign - error found"
}
$outputBox.text = @()
$outputBox.text = "Gathering User assigned to VDI info - Please wait...." | Out-String
$VDIUser = $InputBox.text
$user = $InputBox.text
# Gets all Virtual Desktops
$desktopsall = get-brokerdesktop -AdminAddress $DDC -MaxRecordCount 50000 | Select MachineName,AssociatedUserNames,LastConnectionTime,PowerState,SessionStateSessionUserName,PublishedName,DesktopGroupName,Tags
$machine = ''
$countvdi = 0
## User enabled/disabled validation
$ADEnabled = (Get-ADUser $VDIUser -Properties * | Select-Object Enabled | FT -HideTableHeaders | Out-String).Trim()
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.text += "------ Validate if User is enabled"
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.text += "User: " + $VDIUser + " active status is: " + $ADEnabled | Out-String
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += "----- The Following VDIs are assigned to user: $VDIUser"
$outputBox.AppendText("`n")
# Gets extra information on Virtual Desktop usage
foreach ($desktops in $desktopsall) {
$AssociatedUserNamesTrimmed = $desktops.AssociatedUserNames -replace "$DomainTrim", ""
If ($AssociatedUserNamesTrimmed -eq $VDIUser) {
$machine += $desktops.machinename
$ConTime += $desktops.LastConnectionTime | Out-String
$VirApp += $desktops.PublishedName
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += $desktops.machinename + " - tagged (" + $desktops.Tags + ")" + " - DeliveryGroup: " + $desktops.DesktopGroupName + " - PowerState: " + $desktops.powerstate + " - SessionState: " + $desktops.SessionState + " - Last logged on: " + $desktops.LastConnectionTime
$outputBox.AppendText("`n")
$countvdi += 1
}
}
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += "----- $VDIUser is Assigned to the following AD Groups"
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
#Checking of old AD groups
foreach ($group in $groups) {
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty SamAccountName
If ($machine) {
If ($members -contains $user) {
$outputBox.Text += $group
$outputBox.AppendText("`n")
} Else {
continue
}
}
}
#Checking AD groups that users needs to be in for getting a VDI assigned
foreach ($groupTIER2 in $groupsTIER2) {
$members = Get-ADGroupMember -Identity $groupTIER2 -Recursive | Select -ExpandProperty SamAccountName
If ($machine) {
If ($members -contains $user) {
$outputBox.Text += $groupTIER2
$outputBox.AppendText("`n")
} Else {
continue
}
}
}
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBoxCount.Text = $countvdi
}
############################################## VDI Check user assignment Function END ###############################
############################################## VDI Check user assignment contains inputFunction ####################################
function VDIAssignUserNameContain{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIAssignUserNameContain - error found"
}
$outputBox.text += "Gathering User assigned to VDI info - Please wait...." | Out-String
$VDIUser = $InputBox.text
# Gets all Virtual Desktops where the USERNAME is assigned a Virtual Desktops
$DesktopUsersVDIM = Get-BrokerMachine -AdminAddress $DDC -MaxRecordCount 5000 | Select-Object MachineName,Tags,DesktopGroupName, @{Name='AssociatedUserNames';Expression={[string]::join(“;”, ($_.AssociatedUserNames))}} | Where-Object {$_.AssociatedUserNames -like "*$VDIUser*"} | FT
#Output on screen
$outputBox.Text = "VDIs containing Associated USERNAME with: $VDIUser "
$outputBox.AppendText("`n")
$outputBox.Text += $DesktopUsersVDIM | Out-String
# Output the count
$outputBoxCount.Text = $DesktopUsersVDIM.Count
}
############################################## VDI Check user assignment contains input Function END ###############################
############################################## Check user assignment to a specific VDI Function ####################################
function VDIUserAssign{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIUserAssign - error found"
}
$outputBox.text = "Gathering User assigned to VDI - Please wait...." | Out-String
$objStatusBar.Text = "Gathering User assigned to VDI - Please wait...."
# Input is the Virtual Desktop name
$VDIName = $InputBoxVDIName.text
# Getting all Virtual Desktops
$desktops = get-brokerdesktop -AdminAddress $DDC -MaxRecordCount 5000 | Select MachineName,Tags,AssociatedUserNames,SessionUserName,PowerState
$AssociatedUser = ''
foreach ($desktop in $desktops) {
If ($desktop.MachineName -like "*$VDIName*") {
$VDIUserName = $desktop.AssociatedUserNames
$Tag = $desktop.Tags
$outputBox.Text = $VDIName + " ($Tag) " + " is assigned to " + $VDIUserName + " and active sessionUser is: " + $desktop.SessionUserName
break
}
}
$objStatusBar.Text = "Gathering User assigned to VDI - Please wait...."
}
############################################## Check user assignment to a specific VDI Function END ###############################
############################################## Find Users assigned to VDIs from List Function ####################################
function FindUsersFromVDIList{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIUserAssign - error found"
}
$outputBox.text = "Gathering Users assigned to VDIs from list - Please wait...." | Out-String
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$objStatusBar.Text = "Gathering Users assigned to VDIs from list - Please wait...."
## For importing a TXT file with only the Virtual Desktop Names without the DOMAIN extension
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
## If you want to redirect to specific folder
InitialDirectory = "c:\Temp"
## If you want to user Environment Path like "Desktop/ My Documents"
##InitialDirectory = [Environment]::GetFolderPath('Desktop')
## If you want to add any Title to your Dialog Box
Title = "Select the file to import - chose between xlsx,csv,txt"
##If you want to add file filter to your File Browser windows
Filter = 'Select File |*.xlsx;*.txt;*.csv'
#Filter = 'Select File |*.mkv'
}
$FileBrowser.ShowDialog()
#$File = $FileBrowser.Filename
$desktops = Get-Content $FileBrowser.Filename
$desktopsVDIs = get-brokerdesktop -AdminAddress $DDC -MaxRecordCount 5000 | Select MachineName,Tags,AssociatedUserNames
foreach ($desktopVDI in $desktopsVDIs) {
foreach ($desktop in $desktops) {
If ($desktopVDI.MachineName -like "*$desktop*") {
$VDIUserName = $desktopVDI.AssociatedUserNames
#$Tag = $desktop.Tags
$outputBox.Text += $desktop + " is assigned to " + $VDIUserName
#Write-Host = "$desktop is assigned to VDI: $VDIUserName"
$outputBox.AppendText("`n")
}
}
}
$objStatusBar.Text = "Gathering Users assigned to VDIs from list generated - Please wait...."
}
############################################## Find Users assigned to VDIs from List Function END ###############################
############################################## VDI Standard Powered Off Function ####################################
function VDISTDPowerstate{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDISTDPowerstate - error found"
}
$outputBox.text = "Gathering Power State VDI info - Please wait...." | Out-String
$vmcount = 0
$VMList = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 50000 -PowerState Off | Select-Object MachineName,LastConnectionTime,AssociatedUserNames,InMaintenanceMode,PowerState,SessionUserName | Sort-Object MachineName
Foreach ($vm in $VMList) {
[PSCustomObject]@{
Server = $vm.MachineName
"Last Connection time" = $vm.LastConnectionTime
"Maint Mode" = $vm.InMaintenanceMode
"Associated UserName" = $vm.AssociatedUserNames
}
if ($vm.associatedusernames = {})
{
$vmcount +=1
}
}
$outputBox.Text = "Virtual Desktops Powerstate"
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += $VMList | FT | Out-String | Sort-Object MachineName
$outputBoxCount.Text = $vmcount
}
############################################## VDI Standard Powered Off Function END ###############################
############################################## VDI Specis Information Function ####################################
function VDISpecInfo{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDISpecInfo - error found"
}
$VDIName = $InputBoxVDIName.text
$VDIFullName = $DomainPrefix + $VDIName
$outputBox.text = "Gathering VDI info - Please wait...." | Out-String
# Gets information on the Virtual Desktop from Citrix Studio
$VDI = Get-BrokerMachine -MachineName $VDIFullName -adminaddress $DDC -ErrorAction SilentlyContinue
IF ($VDI -eq $null){
$outputBox.Text = "VDI: " + $VDIName + " - does not exist"
}
Else{
$outputBox.Text = "Information for Virtual Desktop: " + $VDIName
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += $VDI | Out-String
}
}
############################################## VDI Specis Information Function END ###############################
############################################## Delivery Groups Function ####################################
function DelGrp{
# For debugging purpose
if ($debug -eq $True){
write-host "In function DelGrp - error found"
}
$outputBox.text = "Gathering Citrix Delivery Groups info - Please wait...." | Out-String
$Groups = Get-BrokerDesktopGroup -adminaddress $DDC -Filter {SessionSupport -eq 'SingleSession'} -MaxRecordCount 5000 | Select Name
Foreach ($group in $groups) {
[PSCustomObject]@{
PublishedName = $group.PublishedName
}
$vmcount +=1
}
$outputBox.Text = $Groups | FT | Out-String
$outputBoxCount.Text = $vmcount
}
############################################## Delivery Groups Function END ###############################
############################################## Machine Catalog Function ####################################
function MacCat{
# For debugging purpose
if ($debug -eq $True){
write-host "In function MacCat - error found"
}
$outputBox.text = "Gathering Citrix Machine Catalogs info - Please wait...." | Out-String
$Groups = Get-BrokerCatalog -adminaddress $DDC -MaxRecordCount 5000 | Select Name
Foreach ($group in $groups) {
[PSCustomObject]@{
Name = $group.Name
}
$vmcount +=1
}
$outputBox.Text = $Groups | FT | Out-String
$outputBoxCount.Text = $vmcount
}
############################################## Machine Catalog Function END ###############################
############################################## VDI Active State function ###############################
function VDIW10WAS{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIW10WAS - error found"
}
$outputBox.text = "Gathering Virtual Desktops Active State info List - Please wait...." | Out-String
$BrokerDesktops = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 5000 -Filter {MachineName -like $VDIPrefix -and SessionState -eq $null -and PowerState -eq 'on'} | Select-Object -Property MachineName,Tags,LastDeregistrationTime,LastConnectionTime,LastConnectionUser,CatalogName,SessionState,SessionUserName,PowerState | Sort-Object LastDeregistrationTime,MachineName | FT -AutoSize
$vmcount = 0
$CountBrokerDesktops = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 5000 -Filter {MachineName -like $VDIPrefix -and SessionState -eq $null -and PowerState -eq 'on'} | Select-Object -Property MachineName,Tags,LastConnectionTime,LastConnectionUser,DesktopGroupName,SessionState,SessionUserName,PowerState | Sort-Object MachineName
Foreach ($vm in $CountBrokerDesktops) {
#Count total number of VDI Standard
$vmcount +=1
}
if ($CountBrokerDesktops -eq $NULL){
$outputBox.Text = "There are noVirtual Desktops without active User Session powered on"
}
Else{
$outputBox.Text = $BrokerDesktops | FT | Out-String
}
$outputBoxCount.Text = $CountBrokerDesktops.Count
}
############################################## VDI Active State END ###############################
############################################## VDI List VDI Names Only Function ###############################
function VDIListNameOnly{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIListNameOnly - error found"
}
$outputBox.text = "Gathering Virtual Desktop Names List - Please wait...." | Out-String
$VMListTotal = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 5000 -filter {DesktopGroupUid -ne $null} | where MachineName -like $VDIPrefix | Select-Object -Property MachineName,AgentVersion,CatalogName,SessionState, SessionUserName,PowerState,Tags,@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}} | Sort-Object CatalogName, MachineName, AgentVersion #| FT -AutoSize
$TableWidth = @{Expression={$_.Col1}; Label="MachineName"; Width=30},
@{Expression={$_.Col2}; Label="AgentVersion"; Width=30},
@{Expression={$_.Col3}; Label="Associated Usernames"; Width=30}
$outputBox.Text = "This is the current total Virtual Desktop list for each Delivery Group / Machine Catalog"
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += $VMListTotal | FT | Out-String
$outputBoxCount.Text = $VMListTotal.count
$CountVDI = $VMListTotal.count
}
############################################## VDI List VDI Names Only Function END ###############################
############################################## Output all VDI information to Excel Function ###############################
function AllVDIandUsertoExcel{
# For debugging purpose
if ($debug -eq $True){
write-host "In function AllVDIandUsertoExcel - error found"
}
$outputBox.text = "Gathering All VDI information List - Please wait...." | Out-String
$AllVDI_User_VMListTotal = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 5000 -filter {DesktopGroupUid -ne $null} | where MachineName -like $VDIPrefix | Select-Object -Property MachineName,CatalogName,@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}} | Sort-Object MachineName | Export-Excel -path ("c:\temp\All_VDI_List_Report.xlsx") -worksheetname "All_VDI_List" -TableStyle Medium16 -AutoSize
$outputBox.Text = "Excel sheet copied to c:\temp\All_VDI_List_Report.xlsx"
}
############################################## Output all VDI information to Excel Function END ###############################
############################################## Function List all disabled users that are in the Delivery Groups for VDIs #########################
Function DisabledUsersVDI {
# For debugging purpose
if ($debug -eq $True){
write-host "In function DisabledUsersVDI - error found"
}
# Clean Output Field
$outputBox.Text = @()
# Output file path
$outputFile = "C:\Temp\Disabled_users.txt"
#$outputFileCSV = "C:\Temp\Disabled_users.csv"
# Initialize an empty array to store disabled users
$disabledUsers = @()
$ListDisUsersOnly = @()
# Loop through each AD group
foreach ($group in $groups) {
# Get the members of the group
$members = Get-ADGroupMember -Identity $group -Recursive |
Where-Object { $_.objectClass -eq "user" }
# Loop through each member and check if they are disabled
foreach ($member in $members) {
$user = Get-ADUser -Identity $member.SamAccountName -Properties Enabled |
Select-Object SamAccountName, Enabled
# Check if the user is disabled
if (-not $user.Enabled) {
$disabledUsers += $user
$ListDisUsersOnly += $user.SamAccountName + " and member of : " + $group
}
}
}
$outputBox.Text = "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += "Listed below are the users currently disabled in the VDI Delivery Groups"
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += $ListDisUsersOnly | FT | Out-String
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += "Total amount of Users " + $ListDisUsersOnly.count
$outputBox.AppendText("`n")
$outputBox.Text += "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += "File copied to -> C:\Temp\Disabled_users.txt"
# Export the disabled users to a text file
#$ListDisUsersOnly | Export-Csv -Path $outputFileCSV -NoTypeInformation
$ListDisUsersOnly | Out-File -FilePath $outputFile
# Inform the user about the script completion
#Write-Host "Disabled users have been exported to $outputFile."
}
############################################## Function List all disabled users that are in the Delivery Groups for VDIs End #########################################
################################### VDI Search by TAG Function Start ###################################
function VDITAG{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDITAG - error found"
}
$vmcount = 0
### Out-gridview for user to select the citrix tag they want to find which members (Desktops) are tagged
$Tag_to_Search = $InputBox.text
$Members_of_Tag = Get-BrokerMachine -AdminAddress $DDC -Tag $Tag_to_Search -MaxRecordCount 100000 | Select HostedMachineName, Tags, DesktopGroupName, AssociatedUserNames
foreach ($Member in $Members_of_Tag) {
$vmcount +=1
}
### Grabbing all the members (Desktops) that are tagged with the selected tag
### If there are no members of the tag it will send output to console otherwise it will send an out-gridview
If ($null -eq $Members_of_Tag){
#Write-Host "No members of the selected TAG" -BackgroundColor Red -ForegroundColor White
$outputBox.Text = "No members of the selected TAG: " + $Tag_to_Search
}
Else{
$outputBox.Text = "---------------------------------------------------------------------"
$outputBox.AppendText("`n")
$outputBox.Text += "Listed below are the VDIs with the TAG: $Tag_to_Search"
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += $Members_of_Tag | FT | Out-String
}
$outputBoxCount.Text = $vmcount
}
################################### VDI Search by TAG Function End ###################################
################################### VDI TAG List Function Start ###################################
function VDITAGList{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDITAGList - error found"
}
$Tag_to_Search = Get-BrokerTag -AdminAddress $DDC | Select Name | FT #Description | Out-GridView -Title "Select the Citrix Tag you want to grab members for" -OutputMode Single
$outputBox.Text = $Tag_to_Search | FT | Out-String
}
################################### VDI TAG List Function End ###################################
################################### ShutDown Single Virtual Desktop by Name Function ################################
function VDIShutDown{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIShutDown - error found"
}
$VDIMachineName = $InputBoxVDIName.text
$VDI = $DomainPrefix + $VDIMachineName
New-BrokerHostingPowerAction -Action Shutdown -MachineName $VDI -ActualPriority 1
$outputBox.Text = "Shutting down VDI: " + $VDIMachineName
$objStatusBar.Text = "Shutting down VDI: " + $VDIMachineName
}
################################### ShutDown VDI by Name Function End##############################
############################################## Shut Down Virtual Desktop function ###############################
function VDIShutDownActiveNoSession{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIShutDownActiveNoSession - error found"
}
$outputBox.text = "Shutting down Powered On Standard VDI without Active userSessions - Please wait...." | Out-String
$vmcount =0
$objStatusBar.Text = @()
# Create c:\temp folder if it does not exist
$path = "C:\temp\"
If (!(test-path $path))
{
md $path
}
$VDIMachinesActive = Get-BrokerDesktop -adminaddress $DDC -MaxRecordCount 50000 -Filter {MachineName -like $VDIPrefix -and SessionState -eq $null -and PowerState -eq 'on'} | Select-Object MachineName | FT -HideTableHeaders | Out-File -FilePath c:\temp\VDIListAutoShutDown.txt
$VDIS = Get-Content c:\temp\VDIListAutoShutDown.txt
foreach ($vdi in $VDIS) {
New-BrokerHostingPowerAction -Action Shutdown -MachineName $vdi -Verbose
$outputBox.AppendText("`n")
$outputBox.Text += "Shutting down VDI: " + $vdi
$outputBox.AppendText("`n")
$outputBox.Text += "VDIs has now been signaled to ShutDown"
$objStatusBar.Text += "Shutting down VDI: " + $vdi
}
$outputBoxCount.Text = $VDIMachinesActive.Count
}
############################################## VDI Active State END ###############################
################################### VDI ShutDown from LIST Function ################################
function VDIShutDownList{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIShutDownList - error found"
}
## Import file using file explorer
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
## File input is: Domain\MACHINENAME
## If you want to redirect to specific folder
InitialDirectory = "c:\Temp"
## If you want to user Environment Path like "Desktop/ My Documents"
#InitialDirectory = [Environment]::GetFolderPath('Desktop')
## If you want to add any Title to your Dialog Box
Title = "Select the file to import - chose between xlsx,csv,txt"
##If you want to add file filter to your File Browser windows
Filter = 'Select File |*.xlsx;*.txt;*.csv'
#Filter = 'Select File |*.mkv'
}
$FileBrowser.ShowDialog()
$File = $FileBrowser.Filename
$outputBox.Text = @()
If( !$File )
{ $outputBox.Text += "File Import was cancelled ....." }
Else {
# Import the VDI list
$VDIList = Get-Content -Path $File
foreach ($VDI in $VDIList) {
if (!$VDI){
continue
}
Else{
New-BrokerHostingPowerAction -AdminAddress $DDC -Action Shutdown -MachineName $VDI -ActualPriority 1
#Write-Host = "Rebooting VDI: " + $VDI
$outputBox.Text += $VDI + " Has been signaled to shut down"
$outputBox.AppendText("`n")
$outputBox.AppendText("`n")
$outputBox.Text += "Shutting Down VDI: " + $VDI
$outputBox.AppendText("`n")
$objStatusBar.Text = "Shutting Down VDI: " + $VDI
}
}
}
$outputBox.AppendText("`n")
$outputBox.Text += "All VDIs in the list has been signaled to SHut Down!!"
}
################################### VDI ShutDown from LIST Function End##############################
################################### Start VDI by Name Function ################################
function VDIStart{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIStart - error found"
}
$VDIMachineName = $DomainPrefix + $InputBoxVDIName.text
New-BrokerHostingPowerAction -Action TurnOn -MachineName $VDIMachineName
$outputBox.Text = "Starting up VDI: " + $VDIMachineName
$objStatusBar.Text = "Starting up VDI: " + $VDIMachineName
}
################################### Start VDI by Name Function End##############################
################################### Add User to Specific VDI function ###############################
function VDIAddUser{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIAddUser - error found"
}
# Add the Users to the specific VDI
$Username = $InputBox.Text
$VDIName = $InputBoxVDIName.Text
$outputBox.text = "Adding user: " + $Username + " to the VDI: " + $VDIName + "- Please wait...." | Out-String
$objStatusBar.Text = "Adding user: " + $Username + " to the VDI: " + $VDIName + "- Please wait...."
#Add DomainPrefix to username
$FinalUserName = $DomainPrefix + $Username
#Add DomainPrefix to VDI name
$FinalVDIName = $DomainPrefix + $VDIName
add-BrokerUser $FinalUserName -Machine $FinalVDIName
$outputBox.text = "User: " + $FinalUserName + " added to: " + $FinalVDIName | Out-String
$objStatusBar.Text = "User: " + $FinalUserName + " added to: " + $FinalVDIName
}
############################################## Add User to Specific VDI function END ###############################
################################### Remove User from Specific VDI function ###############################
function VDIRemoveUser{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIRemoveUser - error found"
}
# Remove the User from the specific VDI
$outputBox.text = "Removing user from the VDI - Please wait...." | Out-String
$objStatusBar.Text = "Removing user from the VDI - Please wait...."
$Username = $InputBox.Text
$VDIName = $InputBoxVDIName.Text
#Add DomainPrefix to username
$FinalUserName = $DomainPrefix + $Username
#Add DomainPrefix to VDI name
$FinalVDIName = $DomainPrefix + $VDIName
Remove-BrokerUser $FinalUserName -Machine $FinalVDIName
$outputBox.text = "User: " + $FinalUserName + " removed from: " + $FinalVDIName | Out-String
$objStatusBar.Text = "User: " + $FinalUserName + " removed from: " + $FinalVDIName
}
############################################## Remove User from Specific VDI Function END ###############################
################################### Remove OBSOLETE User from Specific VDI function ###############################
function VDIRemoveUserObsolete{
# For debugging purpose
if ($debug -eq $True){
write-host "In function VDIRemoveUserObsolete - error found"
}
# Remove the OBSOLETE Domain Users from the specific VDI - Account Like S-1-5-21-1659004503-2077806209-682003330-3711286
$outputBox.text = "Removing user from the VDI - Please wait...." | Out-String
$objStatusBar.Text = "Removing user from the VDI - Please wait...."
$Username = $InputBox.Text
$VDIName = $InputBoxVDIName.Text
#Add Vetas to VDI name
$FinalVDIName = $DomainPrefix + $VDIName
Remove-BrokerUser $Username -Machine $FinalVDIName
$outputBox.text = "OBSOLETE User: " + $FinalUserName + " removed from: " + $FinalVDIName | Out-String
$objStatusBar.Text = "OBSOLETE User: " + $FinalUserName + " removed from: " + $FinalVDIName
}
############################################## Remove User from Specific VDI Function END ###############################
################################### Find Published Applications containing specific AD Groups function ###############################
function FindADGroupforApp{
$ADGroup = $InputBox.Text
$ApplicationList = @()
#Find all information for all applications
#Get-BrokerApplication -AdminAddress $DDC -AssociatedUserFullName "*$ADGroup*" | Select AdminFolderName,@{l="AdminFolderUid";e={$_.AdminFolderUid -join ","}},@{l="AllAssociatedDesktopGroupUUIDs";e={$_.AllAssociatedDesktopGroupUUIDs -join ","}},@{l="AllAssociatedDesktopGroupUids";e={$_.AllAssociatedDesktopGroupUids -join ","}},ApplicationName,ApplicationType,@{l="AssociatedApplicationGroupUUIDs";e={$_.AssociatedApplicationGroupUUIDs -join ","}},@{l="AssociatedApplicationGroupUids";e={$_.AssociatedApplicationGroupUids -join ","}},@{l="AssociatedDesktopGroupPriorities";e={$_.AssociatedDesktopGroupPriorities -join ","}},@{l="AssociatedDesktopGroupUUIDs";e={$_.AssociatedDesktopGroupUUIDs -join ","}},@{l="AssociatedDesktopGroupUids";e={$_.AssociatedDesktopGroupUids -join ","}},@{l="AssociatedUserFullNames";e={$_.AssociatedUserFullNames -join ","}},@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}},@{l="AssociatedUserSIDs";e={$_.AssociatedUserSIDs -join ","}},@{l="AssociatedUserUPNs";e={$_.AssociatedUserUPNs -join ","}},BrowserName,ClientFolder,CommandLineArguments,CommandLineExecutable,@{l="ConfigurationSlotUids";e={$_.ConfigurationSlotUids -join ","}},CpuPriorityLevel,Description,Enabled,HomeZoneName,HomeZoneOnly,HomeZoneUid,IconFromClient,IconUid,IgnoreUserHomeZone,LocalLaunchDisabled,@{l="MachineConfigurationNames";e={$_.MachineConfigurationNames -join ","}},@{l="MachineConfigurationUids";e={$_.MachineConfigurationUids -join ","}},MaxPerMachineInstances,MaxPerUserInstances,MaxTotalInstances,@{l="MetadataKeys";e={$_.MetadataKeys -join ","}},@{l="MetadataMap";e={$_.MetadataMap -join ","}},Name,PublishedName,SecureCmdLineArgumentsEnabled,ShortcutAddedToDesktop,ShortcutAddedToStartMenu,StartMenuFolder,@{l="Tags";e={$_.Tags -join ","}},UUID,Uid,UserFilterEnabled,Visible,WaitForPrinterCreation,WorkingDirectory
#Find only Application Name for the assigned user/ADGroup
$ApplicationList = Get-BrokerApplication -AdminAddress $DDC -MaxRecordCount 50000 -AssociatedUserFullName "*$ADGroup*" | Select Name
$outputBox.text = $ApplicationList | Out-String
$objStatusBar.Text = "Published Applications List generated"
}
############################################## Find Published Applications containing specific AD Groups Function END ###############################
############################################## Published Application Report CSV/TXT/XLSX function ###############################
function PARepCSV{
#clear field
# For debugging purpose
if ($debug -eq $True){
write-host "In function PARepCSV - error found"
}
$OutPath = $InputBox.Text
#### This function deliveres Published Applications with all information to CSV, XLSX and TXT files
### Enter FILENAME in the inputbox.text field
## Create total list incl all information to CSV
Get-BrokerApplication -AdminAddress $DDC -MaxRecordCount 100000 | Select AdminFolderName,@{l="AdminFolderUid";e={$_.AdminFolderUid -join ","}},@{l="AllAssociatedDesktopGroupUUIDs";e={$_.AllAssociatedDesktopGroupUUIDs -join ","}},@{l="AllAssociatedDesktopGroupUids";e={$_.AllAssociatedDesktopGroupUids -join ","}},ApplicationName,ApplicationType,@{l="AssociatedApplicationGroupUUIDs";e={$_.AssociatedApplicationGroupUUIDs -join ","}},@{l="AssociatedApplicationGroupUids";e={$_.AssociatedApplicationGroupUids -join ","}},@{l="AssociatedDesktopGroupPriorities";e={$_.AssociatedDesktopGroupPriorities -join ","}},@{l="AssociatedDesktopGroupUUIDs";e={$_.AssociatedDesktopGroupUUIDs -join ","}},@{l="AssociatedDesktopGroupUids";e={$_.AssociatedDesktopGroupUids -join ","}},@{l="AssociatedUserFullNames";e={$_.AssociatedUserFullNames -join ","}},@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}},@{l="AssociatedUserSIDs";e={$_.AssociatedUserSIDs -join ","}},@{l="AssociatedUserUPNs";e={$_.AssociatedUserUPNs -join ","}},BrowserName,ClientFolder,CommandLineArguments,CommandLineExecutable,@{l="ConfigurationSlotUids";e={$_.ConfigurationSlotUids -join ","}},CpuPriorityLevel,Description,Enabled,HomeZoneName,HomeZoneOnly,HomeZoneUid,IconFromClient,IconUid,IgnoreUserHomeZone,LocalLaunchDisabled,@{l="MachineConfigurationNames";e={$_.MachineConfigurationNames -join ","}},@{l="MachineConfigurationUids";e={$_.MachineConfigurationUids -join ","}},MaxPerMachineInstances,MaxPerUserInstances,MaxTotalInstances,@{l="MetadataKeys";e={$_.MetadataKeys -join ","}},@{l="MetadataMap";e={$_.MetadataMap -join ","}},Name,PublishedName,SecureCmdLineArgumentsEnabled,ShortcutAddedToDesktop,ShortcutAddedToStartMenu,StartMenuFolder,@{l="Tags";e={$_.Tags -join ","}},UUID,Uid,UserFilterEnabled,Visible,WaitForPrinterCreation,WorkingDirectory | Export-Csv -Path ("c:\temp\" + $OutPath + "_Report.csv") -NoTypeInformation
## Create total list incl all information to TXT
Get-BrokerApplication -AdminAddress $DDC -MaxRecordCount 100000 | Select AdminFolderName,@{l="AdminFolderUid";e={$_.AdminFolderUid -join ","}},@{l="AllAssociatedDesktopGroupUUIDs";e={$_.AllAssociatedDesktopGroupUUIDs -join ","}},@{l="AllAssociatedDesktopGroupUids";e={$_.AllAssociatedDesktopGroupUids -join ","}},ApplicationName,ApplicationType,@{l="AssociatedApplicationGroupUUIDs";e={$_.AssociatedApplicationGroupUUIDs -join ","}},@{l="AssociatedApplicationGroupUids";e={$_.AssociatedApplicationGroupUids -join ","}},@{l="AssociatedDesktopGroupPriorities";e={$_.AssociatedDesktopGroupPriorities -join ","}},@{l="AssociatedDesktopGroupUUIDs";e={$_.AssociatedDesktopGroupUUIDs -join ","}},@{l="AssociatedDesktopGroupUids";e={$_.AssociatedDesktopGroupUids -join ","}},@{l="AssociatedUserFullNames";e={$_.AssociatedUserFullNames -join ","}},@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}},@{l="AssociatedUserSIDs";e={$_.AssociatedUserSIDs -join ","}},@{l="AssociatedUserUPNs";e={$_.AssociatedUserUPNs -join ","}},BrowserName,ClientFolder,CommandLineArguments,CommandLineExecutable,@{l="ConfigurationSlotUids";e={$_.ConfigurationSlotUids -join ","}},CpuPriorityLevel,Description,Enabled,HomeZoneName,HomeZoneOnly,HomeZoneUid,IconFromClient,IconUid,IgnoreUserHomeZone,LocalLaunchDisabled,@{l="MachineConfigurationNames";e={$_.MachineConfigurationNames -join ","}},@{l="MachineConfigurationUids";e={$_.MachineConfigurationUids -join ","}},MaxPerMachineInstances,MaxPerUserInstances,MaxTotalInstances,@{l="MetadataKeys";e={$_.MetadataKeys -join ","}},@{l="MetadataMap";e={$_.MetadataMap -join ","}},Name,PublishedName,SecureCmdLineArgumentsEnabled,ShortcutAddedToDesktop,ShortcutAddedToStartMenu,StartMenuFolder,@{l="Tags";e={$_.Tags -join ","}},UUID,Uid,UserFilterEnabled,Visible,WaitForPrinterCreation,WorkingDirectory | Out-file -FilePath ("c:\temp\" + $OutPath + "_Report.txt")
## Create total list incl all information to EXCEL
Get-BrokerApplication -AdminAddress $DDC -MaxRecordCount 100000 | Select AdminFolderName,@{l="AdminFolderUid";e={$_.AdminFolderUid -join ","}},@{l="AllAssociatedDesktopGroupUUIDs";e={$_.AllAssociatedDesktopGroupUUIDs -join ","}},@{l="AllAssociatedDesktopGroupUids";e={$_.AllAssociatedDesktopGroupUids -join ","}},ApplicationName,ApplicationType,@{l="AssociatedApplicationGroupUUIDs";e={$_.AssociatedApplicationGroupUUIDs -join ","}},@{l="AssociatedApplicationGroupUids";e={$_.AssociatedApplicationGroupUids -join ","}},@{l="AssociatedDesktopGroupPriorities";e={$_.AssociatedDesktopGroupPriorities -join ","}},@{l="AssociatedDesktopGroupUUIDs";e={$_.AssociatedDesktopGroupUUIDs -join ","}},@{l="AssociatedDesktopGroupUids";e={$_.AssociatedDesktopGroupUids -join ","}},@{l="AssociatedUserFullNames";e={$_.AssociatedUserFullNames -join ","}},@{l="AssociatedUserNames";e={$_.AssociatedUserNames -join ","}},@{l="AssociatedUserSIDs";e={$_.AssociatedUserSIDs -join ","}},@{l="AssociatedUserUPNs";e={$_.AssociatedUserUPNs -join ","}},BrowserName,ClientFolder,CommandLineArguments,CommandLineExecutable,@{l="ConfigurationSlotUids";e={$_.ConfigurationSlotUids -join ","}},CpuPriorityLevel,Description,Enabled,HomeZoneName,HomeZoneOnly,HomeZoneUid,IconFromClient,IconUid,IgnoreUserHomeZone,LocalLaunchDisabled,@{l="MachineConfigurationNames";e={$_.MachineConfigurationNames -join ","}},@{l="MachineConfigurationUids";e={$_.MachineConfigurationUids -join ","}},MaxPerMachineInstances,MaxPerUserInstances,MaxTotalInstances,@{l="MetadataKeys";e={$_.MetadataKeys -join ","}},@{l="MetadataMap";e={$_.MetadataMap -join ","}},Name,PublishedName,SecureCmdLineArgumentsEnabled,ShortcutAddedToDesktop,ShortcutAddedToStartMenu,StartMenuFolder,@{l="Tags";e={$_.Tags -join ","}},UUID,Uid,UserFilterEnabled,Visible,WaitForPrinterCreation,WorkingDirectory | Export-Excel -path ("c:\temp\" + $OutPath + "_Report.xlsx") -worksheetname "$OutPath" -TableStyle Medium16 -AutoSize
$outputBox.text = "Total Published Applications list with all information delivered to C:\temp folder on your C-drive"
}
############################################## Published Application Report CSV/TXT function END###############################
############################################## Export Output to TXT file function ###############################
function ExportOutPutBox{