Skip to content

Instantly share code, notes, and snippets.

@jrdnr
Last active July 15, 2021 18:46
Show Gist options
  • Select an option

  • Save jrdnr/98f04dfc93f91f27b09c16ee46422718 to your computer and use it in GitHub Desktop.

Select an option

Save jrdnr/98f04dfc93f91f27b09c16ee46422718 to your computer and use it in GitHub Desktop.
Retrieve Bitlocker Recovery Keys to Syncro
# Prerequisites: You must have a custom asset field
# Name: "Bitlocker Drives"
# Type: "Text area"
#
try{
# Get Bitlocker Volumes or exit.
$BitLockerVolume = Get-BitLockerVolume -ErrorAction stop
# Create output as [string] for Text area Asset-Field.
$Report = $BitLockerVolume |
ForEach-Object {
$MountPoint = $_.MountPoint
$RecoveryKey = [string]($_.KeyProtector).RecoveryPassword
if ($RecoveryKey.Length -gt 5) {
Write-Output ("Drive $MountPoint recovery key: $RecoveryKey")
}
} | Out-String
if ($Report.Length -ge 56){
if ($env:SyncroModule){
Import-Module $env:SyncroModule
Set-Asset-Field -Name "Bitlocker Drives" -Value $Report
} else {
$Report
}
}
} catch [System.Management.ManagementException] {
"Bitlocker Not Detected"
} catch [System.Management.Automation.CommandNotFoundException] {
"Bitlocker Not Detected"
} catch {
"Unexpected Error"
(($Error[0] | Select-Object -Property Exception | Out-String).trim() -split '\r')[-1]
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment