-
Notifications
You must be signed in to change notification settings - Fork 14
/
Get-HelpDesk.ps1
1336 lines (821 loc) · 46.9 KB
/
Get-HelpDesk.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
Get-HelpDesk is a cmdlet created for system administrators. It is a combination of script options to simpliy common help desk tasks.
.DESCRIPTION
Get-HelpDesk is compromised of multiple script options and does not use any parameters.
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: rosborne@osbornepro.com
.LINK
https://osbornepro.com
https://writeups.osbornepro.com
https://btpssecpack.osbornepro.com
https://github.com/tobor88
https://gitlab.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
https://www.hackthebox.eu/profile/52286
.EXAMPLES
Get-HelpDesk
#>
Function Get-HelpDesk {
param([switch]$Elevated)
Function Test-Admin {
$CurrentUser = New-Object -TypeName Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
} # End Test-Admin
If ((Test-Admin) -eq $False) {
If (!($Elevated)) {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
} # End Else
exit
} # End If
$Timeout = new-timespan -Minutes 480 # Time out of script after 8 hours
Do { # This do is for preventing the script for running longer than 8 hours
$Domain = "<Domain.com>"
$PrimaryDC = "<PDC Hostname>"
$SecondaryDC = "SDC Hostname"
$PrintServers = "<Print Server hostname>"
$AzureAdServer = "<Azure Sync Hostname>"
$Sw = [diagnostics.stopwatch]::StartNew()
Function MenuMaker{
param(
[parameter(Mandatory=$true)][String[]]$Selections,
[switch]$IncludeExit,
[string]$Title = $null)
$Width = If ($Title) {
$Length = $Title.Length; $Length2 = $Selections | ForEach-Object {$_.length} | Sort-Object -Descending | Select-Object -First 1;$Length2,$Length | Sort-Object -Descending | Select-Object -First 1
} # End if
Else {
$Selections | ForEach-Object {$_.length} | Sort-Object -Descending | Select-Object -First 1
} # End Else
$Buffer = if (($Width*1.5) -gt 78) {
[math]::floor((78-$width)/2)
} # End if
else {
[math]::floor($width/4)
} # End else
if($Buffer -gt 6) { $Buffer = 6 }
$MaxWidth = $Buffer*2+$Width+$($Selections.count).length+2
$Menu = @()
$Menu += "╔"+"═"*$maxwidth+"╗"
if($Title){
$Menu += "║"+" "*[Math]::Floor(($maxwidth-$title.Length)/2)+$Title+" "*[Math]::Ceiling(($maxwidth-$title.Length)/2)+"║"
$Menu += "╟"+"─"*$maxwidth+"╢"
}
For($i=1;$i -le $Selections.count;$i++){
$Item = "$(if ($Selections.count -gt 9 -and $i -lt 10){" "})$i`. "
$Menu += "║"+" "*$Buffer+$Item+$Selections[$i-1]+" "*($MaxWidth-$Buffer-$Item.Length-$Selections[$i-1].Length)+"║"
}
If($IncludeExit){
$Menu += "║"+" "*$MaxWidth+"║"
$Menu += "║"+" "*$Buffer+"X - Exit"+" "*($MaxWidth-$Buffer-8)+"║"
}
$Menu += "╚"+"═"*$maxwidth+"╝"
$menu
}
do{
MenuMaker -Selections 'UNLOCK Users Account','RESET Users Password','EXPIRATION of Password','PRINTER Spooler Reset','LIST Installed Applications on a Device','REMOTE Access to a Computer','GROUP Members List','Log User Out of Computer','REBOOT Time','USERNAME to SID','Lookup a Certificate by its Thumbprint','FIRST Name Change','LAST Name Change','Perform a Group Policy Update','Sync Azure and Active Directory','Find a Files Location','Disable Hibernate','Add User to a File or Folders Permssions','JOB Title and Department Change' -Title 'IT Help Desk Tasks' -IncludeExit
$Response = Read-Host 'Select a task to carry out.'
} # End Do
While($Response -notin 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,'x')
#===================================================================================================================================
if ($Response -eq '1') {
Invoke-Command -HideComputerName $PrimaryDC -ScriptBlock {
Import-Module ActiveDirectory
do {
$samAccountName = Read-Host "What is the users Sam Account Name Example: firs.last"
$TestUserExists = Get-AdUser -Identity $samAccountName
} # End do
while (!($TestUserExists))
Write-Host "User account has been confirmed to exist."
try {
$TestUserExists | Unlock-ADAccount -Verbose
Write-Host "-User "$samAccountName" unlocked"
} # End Try
catch {
$Error[0]
Write-Warning "There was an issue unlocking $samAccountName."
} # End Catch
pause
} # End Invoke-Command
Clear-Host
} # End 1 Unlock user account
#===================================================================================================================================
elseif ($Response -eq '2') {
Invoke-Command -HideComputerName $PrimaryDC -ScriptBlock {
Import-Module ActiveDirectory
do {
$Who = Read-Host "Whos password do you want to reset? Example: rob.osborne"
$TestUserExist = Get-AdUser -Identity $Who
} # End do
while (!($TestUserExist))
$ChangeP = Read-Host 'Do you want them to change their password at next logon Answer this as either 0 for False or 1 for True'
$BoolValue = try {
[System.Convert]::ToBoolean($ChangeP)
} # End Try
catch [FormatException] {
$BoolValue = $false
} # End Catch
function Get-RandomCharacters($length, $characters) {
$random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
$private:ofs=""
return [String]$characters[$random]
} # https://activedirectoryfaq.com/2017/08/creating-individual-random-passwords/
function Scramble-String([string]$inputString){
$characterArray = $inputString.ToCharArray()
$scrambledStringArray = $characterArray | Get-Random -Count $characterArray.Length
$outputString = -join $scrambledStringArray
return $outputString
} # https://activedirectoryfaq.com/2017/08/creating-individual-random-passwords/
$password = Get-RandomCharacters -length 10 -characters 'abcdefghiklmnoprstuvwxyz'
$password += Get-RandomCharacters -length 4 -characters 'ABCDEFGHKLMNOPRSTUVWXYZ'
$password += Get-RandomCharacters -length 3 -characters '1234567890'
$password += Get-RandomCharacters -length 3 -characters '!"§$%&/()=?}][{@#*+'
$password = Scramble-String $password
Write-Host $password
$password = Read-Host "`nEnter the users new password or use the one above." | ConvertTo-SecureString -AsPlainText -Force -Verbose
if (Set-ADAccountPassword $who -Reset -NewPassword $password -PassThru) {
Set-ADUser -Identity $who -ChangePasswordAtLogon $BoolValue
Get-AdUser $who -Properties * | Select-Object -Property name, pass*
Write-Host "Verify their password was changed in the Password Last Set field"
} # End if
} # End Invoke
pause
Clear-Host
} # End 2 Reset a users password
#===================================================================================================================================
elseif ($Response -eq '3') {
Invoke-Command -HideComputerName $SecondaryDC -ScriptBlock {
Write-Host "Example Get-PwdSet rob.osborne"
Function Get-PwdSet{
Param([parameter(Mandatory=$true)][string]$user)
$Use = Get-AdUser $User -Properties PasswordLastSet,PasswordNeverExpires
If ($Use.PasswordNeverExpires -eq $true) {
Write-Host $User "last set their password on " $Use.PasswordLastSet "this account has a non-expiring password" -ForegroundColor Yellow
} # End if
Else {
$Til = (([datetime]::FromFileTime((Get-AdUser $User -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed"))-(Get-Date)).Days
} # End Else
if ($Til -lt "5") {
Write-Host $User "last set their password on " $Use.PasswordLastSet "it will expire again in " $Til " days" -ForegroundColor Red
} # End if
else {
Write-Host $User "last set their password on " $Use.PasswordLastSet "it will expire again in " $Til " days" -ForegroundColor Green
} # End else
} # End Function
do {
$User = Read-Host "Who is the person in question? Example: rob.osborne"
$UserExist = Get-AdUser -Identity $User
} # End do
while (!($UserExist))
Get-PwdSet $User
} # End Invoke-Command
pause
Clear-Host
} # End 3 Lookup password expiration
#===================================================================================================================================
elseif ($Response -eq 4) {
$PrintSpooler = Read-Host -Prompt "Which Print Spooler do you want to restart.`n$PrintServers"
Try {
Restart-Service -InputObject $(Get-Service -ComputerName $printspooler -Name spooler) -Force
Write-Host 'Print Spooler Restarted'
} # End Try
Catch {
if ((Test-NetConnection $PrintSpooler).PingSucceeded) {
Write-Host "There was an issue restarting the print spooler. `nPing test succeeded. `nTrying to restart the service through a different function."
Invoke-Command -HideComputerName $PrintSpooler {Restart-Service -Name Spooler -Force}
Write-Host "Print spooler restarted successfully."
} # End if
else {
Write-Warning "Ping test failed. Connection to print server could not be established."
} # End else
} # End Catch
pause
Clear-Host
} # End 4 Reset print spooler
#===================================================================================================================================
elseif ($Response -eq 5) {
$TheDevice = Read-Host "What computer do you want to view the installed software? `n`nTo view software installed on local computer enter localhost."
if ($TheDevice -notlike $env:COPMUTERNAME) {
Invoke-Command -HideComputerName $TheDevice -ScriptBlock {
Function Get-InstalledSoftware {
<#
.SYNOPSIS
Pull software details from registry on one or more computers
.DESCRIPTION
Pull software details from registry on one or more computers. Details:
-This avoids the performance impact and potential danger of using the WMI Win32_Product class
-The computer name, display name, publisher, version, uninstall string and install date are included in the results
-Remote registry must be enabled on the computer(s) you query
-This command must run with privileges to query the registry of the remote system(s)
-Running this in a 32 bit PowerShell session on a 64 bit computer will limit your results to 32 bit software and result in double entries in the results
.PARAMETER ComputerName
One or more computers to pull software list from.
.PARAMETER DisplayName
If specified, return only software with DisplayNames that match this parameter (uses -match operator)
.PARAMETER Publisher
If specified, return only software with Publishers that match this parameter (uses -match operator)
.EXAMPLE
#Pull all software from c-is-ts-91, c-is-ts-92, format in a table
Get-InstalledSoftware c-is-ts-91, c-is-ts-92 | Format-Table -AutoSize
.EXAMPLE
#pull software with publisher matching microsoft and displayname matching lync from c-is-ts-91
"c-is-ts-91" | Get-InstalledSoftware -DisplayName lync -Publisher microsoft | Format-Table -AutoSize
.FUNCTIONALITY
Computers
#>
param (
[Parameter(
Position = 0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false
)]
[ValidateNotNullOrEmpty()]
[Alias('CN','__SERVER','Server','Computer')]
[string[]]$ComputerName = $env:computername,
[string]$DisplayName = $null,
[string]$Publisher = $null
)
Begin
{
#define uninstall keys to cover 32 and 64 bit operating systems.
#This will yeild only 32 bit software and double entries on 64 bit systems running 32 bit PowerShell
$UninstallKeys = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
}
Process
{
#Loop through each provided computer. Provide a label for error handling to continue with the next computer.
:computerLoop foreach($computer in $computername)
{
Try
{
#Attempt to connect to the localmachine hive of the specified computer
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computer)
}
Catch
{
#Skip to the next computer if we can't talk to this one
Write-Error "Error: Could not open LocalMachine hive on $computer`: $_"
Write-Verbose "Check Connectivity, permissions, and Remote Registry service for '$computer'"
Continue
}
#Loop through the 32 bit and 64 bit registry keys
foreach($uninstallKey in $UninstallKeys)
{
Try
{
#Open the Uninstall key
$regkey = $null
$regkey = $reg.OpenSubKey($UninstallKey)
#If the reg key exists...
if($regkey)
{
#Retrieve an array of strings containing all the subkey names
$subkeys = $regkey.GetSubKeyNames()
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys)
{
#Build the full path to the key for this software
$thisKey = $UninstallKey+"\\"+$key
#Open the subkey for this software
$thisSubKey = $null
$thisSubKey=$reg.OpenSubKey($thisKey)
#If the subkey exists
if($thisSubKey){
try
{
#Get the display name. If this is not empty we know there is information to show
$dispName = $thisSubKey.GetValue("DisplayName")
#Get the publisher name ahead of time to allow filtering using Publisher parameter
$pubName = $thisSubKey.GetValue("Publisher")
#Collect subset of values from the key if there is a displayname
#Filter by displayname and publisher if specified
if( $dispName -and
(-not $DisplayName -or $dispName -match $DisplayName ) -and
(-not $Publisher -or $pubName -match $Publisher )
)
{
#Display the output object, compatible with PowerShell 2
New-Object PSObject -Property @{
ComputerName = $computer
DisplayName = $dispname
Publisher = $pubName
Version = $thisSubKey.GetValue("DisplayVersion")
UninstallString = $thisSubKey.GetValue("UninstallString")
InstallDate = $thisSubKey.GetValue("InstallDate")
} | select ComputerName, DisplayName, Publisher, Version, UninstallString, InstallDate
}
}
Catch
{
#Error with one specific subkey, continue to the next
Write-Error "Unknown error: $_"
Continue
}
}
}
}
}
Catch
{
#Write verbose output if we couldn't open the uninstall key
Write-Verbose "Could not open key '$uninstallkey' on computer '$computer': $_"
#If we see an access denied message, let the user know and provide details, continue to the next computer
if($_ -match "Requested registry access is not allowed"){
Write-Error "Registry access to $computer denied. Check your permissions. Details: $_"
continue computerLoop
}
}
}
}
}
}
Get-InstalledSoftware -Verbose | Select-Object -Property InstallDate, DisplayName
} # End Invoke-Command
} # End If
else {
Function Get-InstalledSoftware {
<#
.SYNOPSIS
Pull software details from registry on one or more computers
.DESCRIPTION
Pull software details from registry on one or more computers. Details:
-This avoids the performance impact and potential danger of using the WMI Win32_Product class
-The computer name, display name, publisher, version, uninstall string and install date are included in the results
-Remote registry must be enabled on the computer(s) you query
-This command must run with privileges to query the registry of the remote system(s)
-Running this in a 32 bit PowerShell session on a 64 bit computer will limit your results to 32 bit software and result in double entries in the results
.PARAMETER ComputerName
One or more computers to pull software list from.
.PARAMETER DisplayName
If specified, return only software with DisplayNames that match this parameter (uses -match operator)
.PARAMETER Publisher
If specified, return only software with Publishers that match this parameter (uses -match operator)
.EXAMPLE
#Pull all software from c-is-ts-91, c-is-ts-92, format in a table
Get-InstalledSoftware c-is-ts-91, c-is-ts-92 | Format-Table -AutoSize
.EXAMPLE
#pull software with publisher matching microsoft and displayname matching lync from c-is-ts-91
"c-is-ts-91" | Get-InstalledSoftware -DisplayName lync -Publisher microsoft | Format-Table -AutoSize
.FUNCTIONALITY
Computers
#>
param (
[Parameter(
Position = 0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false
)] # End Paramter
[ValidateNotNullOrEmpty()]
[Alias('CN','__SERVER','Server','Computer')]
[string[]]$ComputerName = $env:computername,
[string]$DisplayName = $null,
[string]$Publisher = $null
) # End Param
Begin
{
#define uninstall keys to cover 32 and 64 bit operating systems.
#This will yeild only 32 bit software and double entries on 64 bit systems running 32 bit PowerShell
$UninstallKeys = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
} # End Begin
Process
{
#Loop through each provided computer. Provide a label for error handling to continue with the next computer.
:computerLoop foreach($computer in $computername)
{
Try
{
#Attempt to connect to the localmachine hive of the specified computer
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$computer)
} # End Try
Catch
{
#Skip to the next computer if we can't talk to this one
Write-Error "Error: Could not open LocalMachine hive on $computer`: $_"
Write-Verbose "Check Connectivity, permissions, and Remote Registry service for '$computer'"
Continue
} # End Catch
#Loop through the 32 bit and 64 bit registry keys
foreach($uninstallKey in $UninstallKeys)
{
Try
{
#Open the Uninstall key
$regkey = $null
$regkey = $reg.OpenSubKey($UninstallKey)
#If the reg key exists...
if($regkey)
{
#Retrieve an array of strings containing all the subkey names
$subkeys = $regkey.GetSubKeyNames()
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys)
{
#Build the full path to the key for this software
$thisKey = $UninstallKey+"\\"+$key
#Open the subkey for this software
$thisSubKey = $null
$thisSubKey=$reg.OpenSubKey($thisKey)
#If the subkey exists
if($thisSubKey){
try
{
#Get the display name. If this is not empty we know there is information to show
$dispName = $thisSubKey.GetValue("DisplayName")
#Get the publisher name ahead of time to allow filtering using Publisher parameter
$pubName = $thisSubKey.GetValue("Publisher")
#Collect subset of values from the key if there is a displayname
#Filter by displayname and publisher if specified
if( $dispName -and
(-not $DisplayName -or $dispName -match $DisplayName ) -and
(-not $Publisher -or $pubName -match $Publisher )
) # End if start
{
#Display the output object, compatible with PowerShell 2
New-Object PSObject -Property @{
ComputerName = $computer
DisplayName = $dispname
Publisher = $pubName
Version = $thisSubKey.GetValue("DisplayVersion")
UninstallString = $thisSubKey.GetValue("UninstallString")
InstallDate = $thisSubKey.GetValue("InstallDate")
} | select ComputerName, DisplayName, Publisher, Version, UninstallString, InstallDate
} # End if
} # End try
Catch
{
#Error with one specific subkey, continue to the next
Write-Error "Unknown error: $_"
Continue
}
} # End if
} # End Foreach
} # End if
} # End Try
Catch
{
#Write verbose output if we couldn't open the uninstall key
Write-Verbose "Could not open key '$uninstallkey' on computer '$computer': $_"
#If we see an access denied message, let the user know and provide details, continue to the next computer
if($_ -match "Requested registry access is not allowed"){
Write-Error "Registry access to $computer denied. Check your permissions. Details: $_"
continue computerLoop
} # End if
} # End Catch
} # End Foreach
} # End Foreach
} # End Process
} # End Function
Get-InstalledSoftware -Verbose | Select-Object -Property InstallDate, DisplayName
} # End else
pause
Clear-Host
} # End 5 List installed applications
#===================================================================================================================================
elseif ($Response -eq 6) {
$computer = Read-Host -Prompt "Enter their Desktops hostname. Example: DesktopComp06"
$option = Read-Host -Prompt "To add a User enter 1. To Delete a User enter 0"
if ($option -like '1') {
Invoke-Command -HideComputerName $computer {
$user = Read-Host -Prompt "Enter the users SamAccountName. Example: rob.osborne"
net LOCALGROUP "Remote Desktop Users" /ADD "$User"
net LOCALGROUP "Remote Desktop Users"
} # End Invoke-Command
} # End if
elseif ($option -like '0') {
Invoke-Command -HideComputerName $computer {
$user = Read-Host -Prompt "Enter the users SamAccountName. Example: rob.osborne"
net LOCALGROUP "Remote Desktop Users" /DELETE "$User"
net LOCALGROUP "Remote Desktop Users"
} # End Invoke-Command
} # End elseif
pause
Clear-Host
} # End 6 Add or delete user to Remote Desktop Users allowed list
#===================================================================================================================================
elseif ($Response -eq 7) {
Invoke-Command -HideComputerName $PrimaryDC -ScriptBlock {
Import-Module ActiveDirectory
do {
$group = Read-Host -Prompt "What group are you looking for Example: Domain Admins"
$GroupExists = Get-AdGroup -Filter * | Where-Object -Property Name -Like $group
} # End do
while (!($GroupExists))
Write-Host "Group has been verified to exist."
Get-ADUser -Filter * -Properties DisplayName,memberof | ForEach-Object { New-Object PSObject -Property @{
UserName = $_.DisplayName
Groups = ($_.memberof | Get-ADGroup | Where-Object {$_.GroupCategory -eq "Security"} | Select-Object -ExpandProperty Name) -join ","
} # End Properties
} | Select-Object UserName,Groups | Where-Object -Property Groups -like *$group* | Format-Table -Property UserName
} # End Invoke
pause
Clear-Host
} # End 7 List all members of a group
#===================================================================================================================================
elseif ($Response -eq 8) {
$computadora = Read-Host -Prompt 'What is the computers hostname? Example: DesktopComp08'
quser /server:$computadora
$session = Read-Host -Prompt 'What is the Session ID of the user you want logged out? Example: 2'
try {
Invoke-RDUserLogoff -HostServer $computadora -UnifiedSessionId $session -Force -Credential (Get-Credential -Message 'Use Admin Credentials')
} # End Try
catch {
$Error[0]
Write-Host 'Invoke-RdUserLogoff cmdlet failed. Attempting to use Get-WmiObject to log user off.'
(Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computadora).Win32Shutdown(4)
} # End Catch
pause
Clear-Host
} # End 8 Log User off a Device
#====================================================================================================================================
elseif ($Response -eq 9) {
$machine = Read-Host -Prompt "Look up the last reboot time for which device? Example: DesktopComp09"
try {
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $machine | Select-Object -Property csname, lastbootuptime
} # End Try
catch {
Write-Warning "Error issuing Get-CimInstance on device."
$Error[0]
} # End Catch
pause
Clear-Host
} # End 9 Last Reboot Time
#====================================================================================================================================
elseif ($Response -eq 10) {
$user = Read-Host -Prompt 'What is the users name Example: Contoso\rob.osborne'
$objUser = New-Object System.Security.Principal.NTAccount($user)
$objSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
if (!($objSID -eq $null)) {
Write-Host "Resolved user's sid: " $objSID.Value
} # End if
else {
Write-Host "SID Lookup failed."
} # End Else
pause
Clear-Host
} # End 10 Resolve Username to SID
#=====================================================================================================================================
elseif ($Response -eq 11) {
$CertLookup = Read-Host 'What device is the certificate on? Example: DesktopComp13'
Invoke-Command -HideComputerName $CertLookup -ScriptBlock {
$cert = Read-Host -Prompt 'Enter the Certificates Thumbrpint. Example: 1ffbe67543c5a6fffe4d60b8e661671950cdacbd'
Write-Host 'Checking Local Computer'
Get-ChildItem -Path cert:\LocalMachine\My -Recurse | Where-Object -Property Thumbprint -like $cert | Select-Object -Property *
Write-Host 'Checking Currnet User'
Get-ChildItem -Path Cert:\CurrentUser\My -Recurse | Where-Object -Property Thumbprint -like $cert | Select-Object -Property *
} # End Invoke-Command
pause
Clear-Host
} # End 11 Lookup up certificate by its thumbprint
#=====================================================================================================================================
elseif ($Response -eq 12) {
Invoke-Command -HideComputerName $PrimaryDC -ScriptBlock {
Import-Module ActiveDirectory
$Old = Read-Host -Prompt 'What is the users CURRENT first name? Example: Bill'
$First = Read-Host -Prompt 'What is the users NEW first name? Example: Joe'
$Last = Read-Host -Prompt 'What is the users Last name? Example: Smith'
Write-Host "User information is being updated in Active Directory"
Try {
$User = Get-ADUser -Identity ("$Old.$Last") -Properties *
$User | Set-ADUser -Identity "$First $Last" -DisplayName "$First $Last" -GivenName $First -Surname $Last -EmailAddress "$First.$Last@$Domain" -SamAccountName "$First.$Last" -UserPrincipalName "$First.$Last@$Domain"
} # End try
Catch {
Read-Host "An error as occured. Please try again and ensure all the information was entered correctly"
} # End Catch
Write-Host "Allowing Synchronization of user in Azure Environment"
Connect-MsolService
$Statement = Get-MsolDirSyncFeatures -Feature SynchronizeUpnForManagedUsers
if (!$Statement) {
Set-MsolDirSyncFeature -Feature SynchronizeUpnForManagedUsers -Enable $true
} # End if
# Sync AD and Azure
Write-Host "Syncing Azure AD with Active Directory changes"
Invoke-Command -HideComputerName $AzureAdServer -ScriptBlock {
Start-AdSyncSyncCycle -PolicyType Initial
} # End Invoke
} # End ScriptBlock
pause
Clear-Host
} # End 12 Change an existing users first name
#=====================================================================================================================================
elseif ($Response -eq 13) {
Invoke-Command -HideComputerName $PrimaryDC -ScriptBlock {
Import-Module ActiveDirectory
$First = Read-Host -Prompt 'What is the users first name? Example: Joe'
$Old = Read-Host -Prompt 'What is the users OLD last name? Example: Johnson'
$Last = Read-Host -Prompt 'What is the users NEW last name? Example: Smith'
Write-Host "User information is being updated in Active Directory"
Try {
$User = Get-ADUser -Identity ("$First.$Old") -Properties *
$User | Set-ADUser -DisplayName "$First $Last" -GivenName $First -Surname $Last -EmailAddress "$First.$Last@$Domain" -SamAccountName "$First.$Last" -UserPrincipalName "$First.$Last@$Domain"
} # End try
Catch {
Read-Host "An error as occured. Please try again and ensure all the information was entered correctly"
} # End Catch
Write-Host "Allowing Synchronization of user in Azure Environment"
Connect-MsolService
$Statement = Get-MsolDirSyncFeatures -Feature SynchronizeUpnForManagedUsers
if (!$Statement) {
Set-MsolDirSyncFeature -Feature SynchronizeUpnForManagedUsers -Enable $true
}# End If Not
# Sync AD and Azure
Write-Host "Syncing Azure AD with Active Directory changes"
Invoke-Command -HideComputerName $AzureAdServer -ScriptBlock {
Start-AdSyncSyncCycle -PolicyType Initial
} # End Invoke
# Change H Drive Folder name