-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ps1
More file actions
96 lines (72 loc) · 2.82 KB
/
main.ps1
File metadata and controls
96 lines (72 loc) · 2.82 KB
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
Write-Output "`nWelcome to SetAutLoginWindowsUserDomain tool. This script manages key values in HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon to enable/manage autologon for domain users. use under your own responsability`n
http://github.com/audricd/SALWUD `n"
function Test-RegistryValue {
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Value
)
try {
Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
#reg
$reg = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
$checkreg = Test-Path $reg
#values
$aal = 'AutoAdminLogon'
$ddn = 'DefaultDomainName'
$dp = 'DefaultPassword'
$dun = 'DefaultUsername'
#tp regs
#tp AutoAdminLogon
$tpaal = Test-RegistryValue -Path $reg -Value $aal
#tp DefaultDomainName
$tpddn = Test-RegistryValue -Path $reg -Value $ddn
#tp DefaultPassword
$tpdp = Test-RegistryValue -Path $reg -Value $dp
#tp DefaultUserName
$tpdun = Test-RegistryValue -Path $reg -Value $dun
#gp regs
#gp aal
$gpaal = (Get-Itemproperty $reg).$aal
#gp ddn
$gpddn = (Get-Itemproperty $reg).$ddn
#gp dp
$gpdp = (Get-Itemproperty $reg).$dp
#gp dun
$gpdun = (Get-Itemproperty $reg).$dun
#1st step, check if reg exists
$checkregresult = if ($checkreg -eq $true){Write-Output "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon exists."} Else {Write-Output "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon either does not exist or I cannot access it. Stopping process. Try running this with admin rights."; break}
$checkregresult
#function, check if AAL is enabled
$checkaal = if ($gpaal -eq 1){Write-Output "AutoAdminLogon is enabled on $gpdun for the domain $gpddn"} Else {Write-Output "AutoAdminLogon is disabled"}
#function enable AAL
$enableaal = Set-ItemProperty -Path $reg -Name AutoAdminLogon -Value 1
#function disable AAL
$disableaal = Set-ItemProperty -Path $reg -Name AutoAdminLogon -Value 0
do {
[int]$userMenuChoice = 0
while ( $userMenuChoice -lt 1 -or $userMenuChoice -gt 6) {
Write-Host "1. Enable AutoAdminLogon"
Write-Host "2. Set user"
Write-Host "3. Set password"
Write-Host "4. domain"
Write-Host "5. Disable AutoAdminLogon"
Write-Host "6. Exit"
[int]$userMenuChoice = Read-Host "`nPlease choose an option"
switch ($userMenuChoice) {
1{Set-ItemProperty -Path $reg -Name AutoAdminLogon -Value 1}
2{$dun = Read-Host "Input username"; Set-ItemProperty -Path $reg -Name DefaultUserName -Value $dun}
3{$dp = Read-Host "Input password"; Set-ItemProperty -Path $reg -Name DefaultPassword -Value $dp}
4{$ddn = Read-Host "Input domain"; Set-ItemProperty -Path $reg -Name DefaultDomainName -Value $ddn}
5{Set-ItemProperty -Path $reg -Name AutoAdminLogon -Value 0}
}
}
}
while ( $userMenuChoice -ne 6 )