79 lines
2 KiB
PowerShell
79 lines
2 KiB
PowerShell
# Export Bitlocker info
|
|
|
|
# Init
|
|
$REPORT = ""
|
|
$SKIPPED_PROPERTIES = @(
|
|
"CapacityGB",
|
|
"MountPoint",
|
|
"KeyProtector"
|
|
)
|
|
|
|
# Functions
|
|
function Convert-BytesToString ($bytes) {
|
|
If ($bytes -gt 1PB) {
|
|
return ("{0:0.#} PB" -f ($bytes / 1PB) )
|
|
} ElseIf ($bytes -gt 1TB) {
|
|
return ("{0:0.#} TB" -f ($bytes / 1TB) )
|
|
} ElseIf ($bytes -gt 1GB) {
|
|
return ("{0:0.#} GB" -f ($bytes / 1GB) )
|
|
} ElseIf ($bytes -gt 1MB) {
|
|
return ("{0:0.#} MB" -f ($bytes / 1MB) )
|
|
} ElseIf ($bytes -gt 1KB) {
|
|
return ("{0:0.#} KB" -f ($bytes / 1KB) )
|
|
} Else {
|
|
return ("{0} B" -f $bytes)
|
|
}
|
|
}
|
|
|
|
|
|
# Build report
|
|
$system_drive = $env:SystemDrive
|
|
if ($system_drive -eq "X:") {
|
|
# Assuming we're running in WinPE
|
|
$system_drive = "C:"
|
|
}
|
|
Get-BitlockerVolume -MountPoint $system_drive | ForEach-Object {
|
|
$bitlocker_volume = $_
|
|
$REPORT += ("`n`nDrive {0}`n---`n" -f $bitlocker_volume.MountPoint)
|
|
|
|
# Size info
|
|
$volume = Get-Volume -DriveLetter $bitlocker_volume.MountPoint[0]
|
|
$total = Convert-BytesToString ($volume.Size)
|
|
$used = Convert-BytesToString ($volume.Size - $volume.SizeRemaining)
|
|
if ($volume.Size -gt 0) {
|
|
$REPORT += ("Size: {0} ({1} used)`n" -f $total, $used)
|
|
} else {
|
|
$REPORT += "Size: Unknown`n"
|
|
}
|
|
|
|
# Volume info
|
|
$bitlocker_volume |
|
|
Get-Member -MemberType Property |
|
|
Where-Object {! $SKIPPED_PROPERTIES.Contains($_.Name)} |
|
|
ForEach-Object {
|
|
$name = $_.Name
|
|
if ($bitlocker_volume.$name -ne $null) {
|
|
$REPORT += ("{0}: {1}`n" -f $name, $bitlocker_volume.$name)
|
|
}
|
|
}
|
|
|
|
# Key info
|
|
$bitlocker_volume.KeyProtector |
|
|
ForEach-Object {
|
|
$key = $_
|
|
$REPORT += "Key Slot:`n"
|
|
$key |
|
|
Get-Member -MemberType Property |
|
|
ForEach-Object {
|
|
$name = $_.Name
|
|
if ($key.$name -ne $null -and $key.$name -ne "") {
|
|
$REPORT += ("... {0}: {1}`n" -f $name, $key.$name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Show report
|
|
Write-Host $REPORT.Trim()
|
|
|
|
# vim: sts=2 sw=2 ts=2
|