-
Notifications
You must be signed in to change notification settings - Fork 33
/
BuildTheASDSCriptFromGetADMX.ps1
178 lines (151 loc) · 6.53 KB
/
BuildTheASDSCriptFromGetADMX.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
#Author: David Cottingham
#Uses Content From MidnightFreddie https://gist.github.com/midnightfreddie/69d25ddf5ed784d75c1180f12bee84a6
#This script is a little insane, it was made to create another powershell script to check registry settings, based on data pulled from getadmx.com
Function Get-RandomAlphanumericString {
[CmdletBinding()]
Param (
[int] $length = 8
)
Begin{
}
Process{
Write-Output ( -join ((0x30..0x39) + ( 0x41..0x5A) + ( 0x61..0x7A) | Get-Random -Count $length | % {[char]$_}) )
}
}
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials
$Uri = Read-Host 'Please paste a Valid Control URL from getadmx.com'
$InfoPage = Invoke-Webrequest -Uri $Uri
$title = $InfoPage.ParsedHtml.getElementsByTagName("h1") | Select-Object innerText
$InfoPage.ParsedHtml.getElementsByTagName("tbody") | ForEach-Object {
$Headers = @("Type", "Value")
$n=0
$_.getElementsByTagName("tr") | ForEach-Object {
$OutputRow = $_.getElementsByTagName("td") | Select-Object -ExpandProperty InnerText
if ($Headers) {
$OutputHash = [ordered]@{}
for($i=0;$i -lt $OutputRow.Count;$i++) {
$OutputHash[$Headers[$i]] = $OutputRow[$i]
}
New-Object psobject -Property $OutputHash
} else {
$Headers = $OutputRow
}
$n++
New-Variable -Name "Row$n" -Value $OutputHash.Value
}
}
$Random = (Get-RandomAlphanumericString -length 15 | Tee-Object -variable teeTime )
New-Variable -Name $Random -Value $null
$pagetitle = $title.innerText
write-host "The Control Name is $pagetitle" -ForegroundColor Green
write-host "The Registry Hive is $Row1" -ForegroundColor Green
write-host "The Registry Path is $Row2" -ForegroundColor Green
write-host "The Registry Value is $Row3" -ForegroundColor Green
write-host "The Enabled Value is $Row5" -ForegroundColor Green
write-host "The Disabled Value is $Row6" -ForegroundColor Green
$variablelm = '$LM'+$Random
$variableup = '$UP'+$Random
$variablestd = '$'+$Random
$enabled = ''''+$row5+''''
$disabled = ''''+$row6+''''
$ASDRecommended = Read-Host 'What is the ASD Recommended Setting for' $pagetitle '(e for Enabled or d for Disabled)'
write-host "`r`n####################### START #######################`r`n"
if ($ASDRecommended -eq 'e')
{
if ($Row1 -eq 'HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER')
{
write-host $variablelm '= Get-ItemProperty -Path' ''"'Registry::HKLM\$Row2\'"'-Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host $variableup '= Get-ItemProperty -Path' ''"'Registry::HKCU\$Row2\'"'-Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host 'if ('$variablelm '-eq $null -and '$variableup '-eq $null)'
write-host '{'
write-host 'write-host "'$pagetitle 'is not configured" -ForegroundColor Yellow'
write-host '}'
write-host 'if ('$variablelm ' -eq' $enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled in Local Machine GP" -ForegroundColor Green'
write-host '}'
write-host 'if ('$variablelm ' -eq' $disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled in Local Machine GP" -ForegroundColor Red'
write-host '}'
write-host 'if ('$variableup ' -eq ' $enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled in User GP" -ForegroundColor Green'
write-host '}'
write-host 'if ('$variableup ' -eq ' $disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled in User GP" -ForegroundColor Red'
write-host '}'
}
else
{
write-host $variablestd '= Get-ItemProperty -Path' ''"'Registry::$Row1\$Row2\'"' -Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host 'if ('$variablestd '-eq $null)'
write-host '{'
write-host 'write-host "'$pagetitle 'is not configured" -ForegroundColor Yellow'
write-host '}'
write-host ' elseif ('$variablestd ' -eq '$enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled" -ForegroundColor Green'
write-host '}'
write-host ' elseif ('$variablestd ' -eq '$disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled" -ForegroundColor Red'
write-host '}'
write-host ' else'
write-host '{'
write-host 'write-host "'$pagetitle 'is set to an unknown setting" -ForegroundColor Red'
write-host '}'
}
}
if ($ASDRecommended -eq 'd')
{
if ($Row1 -eq 'HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER')
{
write-host $variablelm '= Get-ItemProperty -Path' ''"'Registry::HKLM\$Row2\'"' -Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host $variableup '= Get-ItemProperty -Path' ''"'Registry::HKCU\$Row2\'"' -Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host 'if ('$variablelm '-eq $null -and '$variableup '-eq $null)'
write-host '{'
write-host 'write-host "'$pagetitle 'is not configured" -ForegroundColor Yellow'
write-host '}'
write-host 'if ('$variablelm ' -eq' $enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled in Local Machine GP" -ForegroundColor Red'
write-host '}'
write-host 'if ('$variablelm ' -eq' $disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled in Local Machine GP" -ForegroundColor Green'
write-host '}'
write-host 'if ('$variableup ' -eq ' $enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled in User GP" -ForegroundColor Red'
write-host '}'
write-host 'if ('$variableup ' -eq ' $disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled in User GP" -ForegroundColor Green'
write-host '}'
}
else
{
write-host $variablestd '= Get-ItemProperty -Path' ''"'Registry::$Row1\$Row2\'"' -Name' $Row3 '-ErrorAction SilentlyContinue|Select-Object -ExpandProperty' $Row3
write-host 'if ('$variablestd '-eq $null)'
write-host '{'
write-host 'write-host "'$pagetitle 'is not configured" -ForegroundColor Yellow'
write-host '}'
write-host ' elseif ('$variablestd ' -eq '$disabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is disabled" -ForegroundColor Green'
write-host '}'
write-host ' elseif ('$variablestd ' -eq '$enabled ')'
write-host '{'
write-host 'write-host "'$pagetitle 'is enabled" -ForegroundColor Red'
write-host '}'
write-host ' else'
write-host '{'
write-host 'write-host "'$pagetitle 'is set to an unknown setting" -ForegroundColor Red'
write-host '}'
}
}
write-host "`r`n####################### END #######################`r`n"
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0