PowerShell – Return BitLocker Passwords using Pattern Matching

email me

This will return BitLocker passwords—and only the passwords—using pattern matching.

 
Code.ps1

# MrNetTek 
# eddiejackson.net 
# 9/11/2024
# free for public use 
# free to claim as your own

# Run manage-bde command and capture the output
$manageBdeOutput = & manage-bde -protectors -get C: 2>&1

# Define our password pattern
$passwordPattern = "\b(\d{6}-\d{6}-\d{6}-\d{6}-\d{6}-\d{6}-\d{6}-\d{6})\b"

# Find all matching lines and extract passwords
$passwords = $manageBdeOutput | Select-String -Pattern $passwordPattern | ForEach-Object {
    if ($_ -match $passwordPattern) {
        $matches[1].Trim()
    }
}

# Output BitLocker Passwords
$passwords

# Session Clean up
Remove-Variable -Name 'manageBdeOutput', 'passwordPattern', 'passwords' -ErrorAction SilentlyContinue