帶有PowerShell的Active Directory的導出Bitlocker恢復鍵

Jacki

有IT中斷,我們需要將所有系統進入安全模式並調整一些值。但是,它要求提供BitLocker密碼。不幸的是,我們沒有它,因此我們需要Bitlocker恢復密鑰才能進入系統。在本文中,您將學習如何將Bitlocker恢復鍵從使用PowerShell到CSV文件的Active Directory。

Windows上的Bitlocker恢復

啟動系統時,它要求BitLocker密碼解鎖驅動器。我們沒有這些信息。所以,讓我們單擊Esc鍵用於Bitlocker恢復。

它要求Bitlocker恢復密鑰。

要獲取BitLocker恢復密鑰,您可以在Active Directory中搜索計算機,打開計算機屬性並撤消信息。

您也可以在Active Directory中搜索Bitlocker恢復密鑰ID提起Bitlocker恢復密碼。

填寫密碼ID並拔出BitLocker恢復密碼。

如果您需要所有BITLOCKER恢復密鑰的報告來加快流程呢?讓我們在下一步中看一下。

Export-bitlockerkeys.ps1 PowerShell腳本將將所有計算機Bitlocker恢復鍵從Active Directory導出到CSV文件,並為您提供以下信息的報告:

  1. ComputerName
  2. recoverypassword
  3. recoveryId
  4. 日期
  5. 時間
  6. 傑出名稱
  7. 作業系統

下載export-bitlockerkeys.ps1 powershell腳本並將其放入C:腳本文件夾。

確保文件未阻止以防止運行腳本時的錯誤。在運行PowerShell腳本時,請在文章中閱讀更多信息。

另一個選擇是將下面的代碼複製並粘貼到記事本中。給它名稱export-bitlockerkeys.ps1,然後將其放在C:腳本文件夾。

<#
    .SYNOPSIS
    Export-BitLockerKeys.ps1

    .DESCRIPTION
    Export BitLocker Recovery Keys from Active Directory for all computers or computers in a specific OU to CSV file.

    .LINK
    www.alitajran.com/export-bitlocker-recovery-keys-active-directory-powershell/

    .NOTES
    Written by: ALI TAJRAN
    Website:    alitajran.com
    X:          x.com/alitajran
    LinkedIn:   linkedin.com/in/alitajran

    .CHANGELOG
    V1.00, 09/25/2024 - Initial version
#>

param(
    # Full path for the CSV report (must be provided)
    [Parameter(Mandatory = $true)]
    [string]$OutputPath,

    # Organizational Unit to search for computers (it will search for all computers if not provided)
    [string]$OU = ""
)

# Get the current user's identity
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
# Create a principal object from the identity to check roles
$principal = [Security.Principal.WindowsPrincipal]::new($currentIdentity)

# Check if the current user is an administrator
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "Only Administrators can read BitLocker Recovery Keys." -ForegroundColor Red
    exit
}

# Determine the search base for computers
if ($OU -ne "") {
    $Computers = Get-ADComputer -Filter 'ObjectClass -eq "computer"' -Property Name, DistinguishedName, OperatingSystem -SearchBase $OU | Sort-Object Name
}
else {
    $Computers = Get-ADComputer -Filter 'ObjectClass -eq "computer"' -Property Name, DistinguishedName, OperatingSystem | Sort-Object Name
}

# Initialize report list
$report = [System.Collections.Generic.List[Object]]::new()

foreach ($computer in $Computers) {
    $params = @{
        Filter     = "objectclass -eq 'msFVE-RecoveryInformation'"
        SearchBase = $computer.DistinguishedName
        Properties = 'msFVE-RecoveryPassword', 'whencreated'
    }

    $bitlockerInfo = Get-ADObject @params | Sort-Object -Property WhenCreated -Descending | Select-Object -First 1

    if ($bitlockerInfo) {
        $ReportLine = [PSCustomObject][ordered]@{
            ComputerName      = $computer.Name
            RecoveryPassword  = $bitlockerInfo.'msFVE-RecoveryPassword'
            RecoveryID        = $bitlockerInfo.Name.Substring(26, 36)
            Date              = $bitlockerInfo.Name.Substring(0, 10)
            Time              = $bitlockerInfo.Name.Substring(11, 8)
            DistinguishedName = $Computer.DistinguishedName
            OperatingSystem   = $Computer.OperatingSystem
        }
        $report.Add($ReportLine)
    }
    else {
        $ReportLine = [PSCustomObject][ordered]@{
            ComputerName      = $computer.Name
            RecoveryPassword  = "No BitLocker information found"
            RecoveryID        = "N/A"
            Date              = "N/A"
            Time              = "N/A"
            DistinguishedName = $Computer.DistinguishedName
            OperatingSystem   = $Computer.OperatingSystem
        }
        $report.Add($ReportLine)
    }
}

# Export the list to CSV
try {
    $report | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding utf8
    Write-Host "Report successfully exported to: $OutputPath" -ForegroundColor Green
}
catch {
    Write-Host "Error exporting report to CSV: $_" -ForegroundColor Red -ErrorAction SilentlyContinue
}

這就是外觀。

運行導出bitlockerkeys powershell腳本

從Active Directory中的所有計算機中導出BitLocker恢復鍵。

C:scripts.Export-BitlockerKeys.ps1 -OutputPath "C:tempAllComputers.csv"

從Active Directory中特定OU(組織單元)內的所有計算機中導出Bitlocker恢復鍵。

C:scripts.Export-BitlockerKeys.ps1 -OutputPath "C:tempComputersOU.csv" -OU "OU=WIN10,OU=Computers,OU=Company,DC=exoip,DC=local"

在路徑中打開CSV文件C:溫度使用您喜歡的應用程序。例如,使用Microsoft Excel。

就是這樣!

結論

您了解瞭如何將Bitlocker恢復鍵從PowerShell到CSV文件的Active Directory。推薦方法是通過Active Directory並檢索BitLocker恢復鍵。這樣,一切都停留在廣告中,並且沒有出口。但是,如果您需要獲取所有Bitlocker恢復密碼的列表,並確保成功簽署後重置恢復密碼,這是最好的方法。

您喜歡這篇文章嗎?您可能還喜歡如何創建Active Directory Security評估報告。不要忘記關注我們並分享這篇文章。

閱讀更多:從Active Directory刪除舊的Bitlocker恢復密碼