-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitLocker v1.ps1
More file actions
279 lines (224 loc) · 11 KB
/
BitLocker v1.ps1
File metadata and controls
279 lines (224 loc) · 11 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
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
<#
.DESCRIPTION
Script runs across all computers on the DOMAIN for Bitlocker Compliance,
also checks TPM Module, FIPS Compliance, BIOS and Local Policy Settings.
.OUTPUTS
Report found under $logPath below, default is c:\COD-Logs\COMPUTERNAME\DATETIME
.EXAMPLE
1. PowerShell 5.1 Command Prompt (Admin)
"powershell -Executionpolicy Bypass -File PATH\FILENAME.ps1"
2. Powershell 7.2.1 Command Prompt (Admin)
"pwsh -Executionpolicy Bypass -File PATH\FILENAME.ps1"
.NOTES
Author Perkins
Last Update 1/7/22
Updated 1/7/22 Tested and Validated PowerShell 5.1 and 7.2.1
Powershell 5 or higher
Run as Administrator
.FUNCTIONALITY
PowerShell Language
Active Directory
.Link
https://github.com/COD-Team
YouTube Video https://youtu.be/4LSMP0gj1IQ
#>
Clear-Host
# Get Domain Name, Creates a DomainName Folder to Store Reports
# # Added 1/7/21 Powershell 7.2.1 Compatibility Get-WmiObject not compatible with Powershell 7.2.1
#$ComputerDomain = (Get-WmiObject win32_computersystem).domain
$ComputerDomain = (Get-CimInstance Win32_ComputerSystem).Domain
#### Using Comment (On/Off) choose $DomainComputers you want to use, 3 options
#option 1 = Scans AD and returns all Computers Names
$DomainComputers = Get-ADComputer -Filter {OperatingSystem -like "Windows*"} -Properties Name | Select-Object -ExpandProperty Name
#option 2 = Randomly select which DomainComputers get scanned, Adjust $rcount
<#
$rCount = 2
$DomainComputers = Get-Random -InputObject (Get-ADComputer -Filter {OperatingSystem -like "Windows*"} -Properties Name | Select-Object -ExpandProperty Name ) -Count $rCount
#>
#option 3 = Specific Computers, Update Array.
#$DomainComputers = ('Computer1', 'Computer2')
# Where the Logs will be stored, Adjust as needed UNC Paths will also work to save in your Network Admin Share
#$logpath = "\\SERVER\SHARENAME\COD-Logs\$ComputerDomain\$(get-date -format "yyyyMMdd-hhmmss")"
$logpath = "C:\COD-Logs\$ComputerDomain\$(get-date -format "yyyyMMdd-hhmmss")"
If(!(test-path $logpath))
{
New-Item -ItemType Directory -Force -Path $logpath
}
# Added 1/7/21 PowerShell 7.2.1 Compatibility for Out-File not printing escape characters
if ($PSVersionTable.PSVersion.major -ge 7) {$PSStyle.OutputRendering = 'PlainText'}
#OutputLog is the name if the file for all the results.
$OutputLog = "$logpath\BitLocker.log"
#This Function will execute based on $DomainComputers Option and/or if they are $Online
Function GetBitlocker
{
# Gets all the Bitlocker information for ALL drives.
$GetBL = Get-BitLockerVolume -ErrorAction SilentlyContinue | Select-Object ComputerName, Mountpoint, EncryptionMethod, AutoUnlockEnabled, AutoUnlockKeyStored, Metadataversion, VolumnStatus, ProtectionStatus, LockStatus, EncryptionPercentage, WipePercentage, VolumnType, CapacityGB, KeyProtector
# Gets FIPS Algorithm Policy (Disabled/Enabled)
$FIPS = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy' -Name 'Enabled' -ErrorAction SilentlyContinue | Select-Object -expandproperty Enabled
# Gets all Registry Settings for Bitlocker, Allows you to compare settings to actual.
$GetFVE = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\FVE' -ErrorAction SilentlyContinue | Select-Object UseAdvancedStartup, EnableBDEWithNoTPM, UseTPM, UseTPMPIN, UseTPMKey, UseTPMKeyPIN, MinimumPIN, EncryptionMethodWithXtsOs, EncryptionMethodWithXtsFdv, EncryptionMethodWithXtsRdv
# Gets TPM Information
$GetTPM = Get-TPM
# Gets BIOS information applicable to BitLocker and Computer Type
# Added 1/7/21 Powershell 7.2.1 Compatibility Get-WmiObject not compatible with Powershell 7.2.1
#$BIOSInfo = Get-WimObject -Class Win32_Bios #-ErrorAction SilentlyContinue
$BIOSInfo = Get-CimInstance -Class Win32_Bios -ErrorAction SilentlyContinue
# This Section is all Reporting
$Report=[PSCustomObject] [ordered]@{
'Hostname'= $env:COMPUTERNAME
'Computer Type' = if ($BIOSInfo.SerialNumber -like 'VM*') {'Virtual Computer'} else {'Physical Computer'}
'RegistrySettings' = '#################'
'FIPS' = Switch ($FIPS)
{
0 {'FIPS Disabled'}
1 {'FIPS Enabled'}
Default {'No FIPS Settings Found'}
}
'UseAdvancedStartup' = Switch ($GetFVE.UseAdvancedStartup)
{
0 {'Disabled'}
1 {'Enabled'}
Default {'No Settings Found'}
}
'EnableBDEWithNoTPM' = Switch ($GetFVE.EnableBDEWithNoTPM)
{
0 {'Disabled'}
1 {'Enabled'}
Default {'No Settings Found'}
}
'UseTPM' = Switch ($GetFVE.UseTPM)
{
0 {'Do not allow TPM'}
1 {'Require TPM'}
2 {'Allow TPM'}
Default {'No Settings Found'}
}
'UseTPMPIN' = Switch ($GetFVE.UseTPMPIN)
{
0 {'Do not allow startup PIN with TPM'}
1 {'Require startup PIN with TPM'}
2 {'Allow startup PIN with TPM'}
Default {'No Settings Found'}
}
'UseTPMKey' = Switch ($GetFVE.UseTPMKey)
{
0 {'Do not allow startup KEY with TPM'}
1 {'Require startup KEY with TPM'}
2 {'Allow startup KEY with TPM'}
Default {'No Settings Found'}
}
'UseTPMKeyPIN' = Switch ($GetFVE.UseTPMKeyPIN)
{
0 {'Do not allow startup KEY and PIN with TPM'}
1 {'Require startup KEY and PIN with TPM'}
2 {'Allow startup KEY and PIN with TPM'}
Default {'No Settings Found'}
}
'MinimumPIN' = Switch ($GetFVE.MinimumPIN)
{
{$_ -ge 1 -and $_ -le 3} {'Pin=' + $_ + ' Is less than Min 4'}
{$_ -ge 4 -and $_ -le 20} {'Pin=' + $_ + ' is between Min 4 and Max 20'}
{$_ -ge 21} {'Pin=' + $_ + ' Exceeds Max of 20'}
Default {'No Settings Found'}
}
'EncryptionMethodWithXtsOs' = Switch ($GetFVE.EncryptionMethodWithXtsOs)
{
0 {'UNSPECIFIED'}
1 {'AES_128_WITH_DIFFUSER'}
2 {'AES_256_WITH_DIFFUSER'}
3 {'AES_128'}
4 {'AES_256'}
5 {'HARDWARE_ENCRYPTION'}
6 {'AES_256'}
7 {'XTS_AES_256'}
Default {'No Settings Found'}
}
'EncryptionMethodWithXtsFdv' = Switch ($GetFVE.EncryptionMethodWithXtsFdv)
{
0 {'UNSPECIFIED'}
1 {'AES_128_WITH_DIFFUSER'}
2 {'AES_256_WITH_DIFFUSER'}
3 {'AES_128'}
4 {'AES_256'}
5 {'HARDWARE_ENCRYPTION'}
6 {'AES_256'}
7 {'XTS_AES_256'}
Default {'No Settings Found'}
}
'EncryptionMethodWithXtsRdv' = Switch ($GetFVE.EncryptionMethodWithXtsRdv)
{
0 {'UNSPECIFIED'}
1 {'AES_128_WITH_DIFFUSER'}
2 {'AES_256_WITH_DIFFUSER'}
3 {'AES_128'}
4 {'AES_256'}
5 {'HARDWARE_ENCRYPTION'}
6 {'AES_256'}
7 {'XTS_AES_256'}
Default {'No Settings Found'}
}
'TPMPresent' = Switch ($GetTPM.TPMPresent)
{
'False' {'TPM Not Present'}
'True' {'TPM Present'}
Default {'No TPM Settings Found'}
}
'TPMReady' = Switch ($GetTPM.TPMReady)
{
'False' {'TPM Not Ready'}
'True' {'TPM Ready'}
Default {'No TPM Settings Found'}
}
'TPMEnabled' = Switch ($GetTPM.TPMEnabled)
{
'False' {'TPM Not Enabled'}
'True' {'TPM Enabled'}
Default {'No TPM Settings Found'}
}
'TPMActivated' = Switch ($GetTPM.TPMActivated)
{
'False' {'TPM Not Activated'}
'True' {'TPM Activated'}
Default {'No TPM Settings Found'}
}
'ManufacturerVersion' = $GetTPM.ManufacturerVersion
'Bitlocker Device Settings' = '#################'
}
# Returns Bitlocker settings, no reporting formatting from above, returns all Bitlocker settings
$BLReport = If ($null -eq $GetBL) {'Bitlocker Not Avialable on '+ $env:computername} else {$GetBL}
# $Report includes all items in Report EXCEPT Bitlocker
$Report
# $BLReport returns ALL Bitlocker from ALL Drives, did not feel the need to seperate as a sub report due to enumeration of drives
$BLReport
Write-Output '------------------------------------------------------------------------------' #| Out-File -Append $OutputLOG
}
## END OF GetBitlocker FUNCTION
Measure-Command {
# This section tests all computers in $DomainComputers Array for accessability (Online/Offline) Produces $Online Array
$GetOnline = Invoke-command –ComputerName $DomainComputers -ErrorAction SilentlyContinue –scriptblock {[pscustomobject]@{ result = (Get-Service -name "winRM").count}}
$Online = $GetOnline | Select-Object -ExpandProperty PSComputerName
$Offline = Compare-Object -ReferenceObject $DomainComputers -DifferenceObject $Online | Select-Object -ExpandProperty InputObject
#Display to Screen
if ($Offline -ge 1) {
Write-Host -fore red 'Computers Offline' -Separator "`n"
Write-Host -fore red '-----------------' -Separator "`n"
Write-Host -fore red $Offline -Separator "`n"
Write-Host -fore red '' -Separator "`n"
}
if ($Online -ge 1) {
Write-Host -fore green 'Computers Online' -Separator "`n"
Write-Host -fore green '-----------------' -Separator "`n"
Write-Host -fore green $online -Separator "`n"
}
#Write to File
Write-Output 'Computers Offline' | Out-File -Append $OutputLOG
$Offline | Out-File -Append $OutputLOG
Write-Output '' | Out-File -Append $OutputLOG
Write-Output 'Computers Online' | Out-File -Append $OutputLOG
$Online | Out-File -Append $OutputLOG
# Uses the $Online Array to execute GetBitlocker Function on all Computers Online only
Invoke-Command -ComputerName $Online -ErrorAction SilentlyContinue -ScriptBlock ${Function:GetBitlocker} | Out-File -Append $OutputLOG
write-host -fore green "LOG saved to: $OutputLOG"
write-host -fore green "Script Completed"
}
Start-Process notepad.exe $OutputLog -NoNewWindow