-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckBitlockerStatus.ps1
62 lines (48 loc) · 2.53 KB
/
CheckBitlockerStatus.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
# Define number of cycles after which to calculate remaining time
$cyclesForEstimate = 5
$checkSeconds = 20
$loopCount = 0
$initialPercentage = $null
$timeStamps = @()
Write-Host "Starting BitLocker Status Check:" (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") -ForegroundColor Green
while ($true) {
# Get current timestamp
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
$timeStamps += Get-Date # Store timestamp for loop duration calculations
# Check the BitLocker status on the C: drive
$status = manage-bde -status C: | Select-String "Percentage"
# Display the current status with timestamp
if ($status) {
Write-Host "`r$timestamp - BitLocker Status: $status" -ForegroundColor Yellow -NoNewline
# Extract the current percentage as a number
$currentPercentage = [double]($status.ToString() -replace '[^\d,]', '') -replace ',', '.'
# Initialize percentage tracking
if ($null -eq $initialPercentage) { $initialPercentage = $currentPercentage }
# Increment loop counter
$loopCount++
# Calculate and display expected remaining time after every defined cycle
if ($loopCount -eq $cyclesForEstimate) {
# Calculate average duration per loop in seconds
$averageLoopDuration = (($timeStamps[-1] - $timeStamps[0]).TotalSeconds) / $cyclesForEstimate
# Calculate decryption rate per loop
$decryptionRate = ($initialPercentage - $currentPercentage) / $cyclesForEstimate
# Estimate remaining loops based on decryption rate and remaining percentage
$remainingLoops = ($currentPercentage / $decryptionRate)
$estimatedRemainingTime = [TimeSpan]::FromSeconds($averageLoopDuration * $remainingLoops)
Write-Host "`r$timestamp - Estimated remaining time: $estimatedRemainingTime" -ForegroundColor Cyan
# Reset variables for the next estimation cycle
$initialPercentage = $currentPercentage
$loopCount = 0
$timeStamps.Clear()
}
} else {
Write-Host "$timestamp - Unable to retrieve status or encryption may be off." -ForegroundColor Red
}
# Exit the loop if encryption is fully disabled
if ($status -and $status.ToString().Contains(" 0,0%")) {
Write-Host "$timestamp - Encryption is fully disabled on the C: drive." -ForegroundColor Green
break
}
# Wait for 30 seconds before checking again
Start-Sleep -Seconds $checkSeconds
}