Tìm kiếm trang web

Xuất khóa khôi phục BitLocker từ Active Directory bằng PowerShell


Có sự cố ngừng hoạt động CNTT và chúng tôi cần đưa tất cả hệ thống vào chế độ an toàn và điều chỉnh một số giá trị. Tuy nhiên, nó yêu cầu mật khẩu BitLocker. Thật không may, chúng tôi không có nó nên chúng tôi cần Khóa khôi phục BitLocker để vào hệ thống. Trong bài viết này, bạn sẽ tìm hiểu cách xuất Khóa khôi phục BitLocker từ Active Directory bằng PowerShell sang tệp CSV.

Phục hồi BitLocker trên Windows

Khi khởi động hệ thống, nó sẽ yêu cầu mật khẩu BitLocker để mở khóa ổ đĩa. Chúng tôi không có thông tin đó. Vì vậy, hãy nhấp vào Esc để khôi phục BitLocker.

Nó yêu cầu Khóa khôi phục BitLocker.

Để lấy Khóa khôi phục BitLocker, bạn có thể tìm kiếm máy tính trong Active Directory, mở thuộc tính máy tính và lấy thông tin.

Bạn cũng có thể tìm kiếm ID khóa khôi phục Bitlocker trong Active Directory để lấy mật khẩu khôi phục BitLocker.

Điền ID mật khẩu và lấy mật khẩu khôi phục BitLocker.

Điều gì sẽ xảy ra nếu bạn cần báo cáo về tất cả Khóa khôi phục BitLocker để tăng tốc quá trình? Hãy xem xét điều đó trong bước tiếp theo.

Xuất tập lệnh PowerShell của Khóa khôi phục BitLocker

Tập lệnh PowerShell Xuất BitLockerKeys.ps1 sẽ xuất tất cả Khóa khôi phục BitLocker của máy tính từ Active Directory sang tệp CSV và cung cấp cho bạn báo cáo với thông tin bên dưới:

  1. Tên máy tính
  2. Phục hồiMật khẩu
  3. ID khôi phục
  4. Ngày
  5. Thời gian
  6. Tên phân biệt
  7. Hệ điều hành

Tải xuống tập lệnh PowerShell Xuất-BitLockerKeys.ps1 và đặt tập lệnh đó vào thư mục C:\scripts.

Đảm bảo tệp được bỏ chặn để tránh lỗi khi chạy tập lệnh. Đọc thêm trong bài viết Lỗi không được ký điện tử khi chạy tập lệnh PowerShell.

Một tùy chọn khác là sao chép và dán đoạn mã bên dưới vào Notepad. Đặt tên cho nó là Xuất-BitLockerKeys.ps1 và đặt nó vào thư mục C:\scripts.

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[PSCustomObject]]::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
}

Đây là cách nó trông như thế này.

Chạy tập lệnh PowerShell của BitLockerKeys

Xuất Khóa khôi phục BitLocker từ tất cả các máy tính trong Active Directory.

C:\scripts\.\Export-Bitlocker.ps1 -OutputPath "C:\temp\AllComputers.csv"

Xuất Khóa khôi phục BitLocker từ tất cả các máy tính trong một OU (Đơn vị tổ chức) cụ thể trong Active Directory.

C:\scripts\.\Export-Bitlocker.ps1 -OutputPath "C:\temp\ComputersOU.csv" -OU "OU=WIN10,OU=Computers,OU=Company,DC=exoip,DC=local"

Mở tệp CSV trong đường dẫn C:\temp bằng ứng dụng yêu thích của bạn. Ví dụ: với Microsoft Excel.

Thế thôi!

Đọc thêm: Cách tự động cấu hình hộp thư trong Outlook »

Phần kết luận

Bạn đã tìm hiểu cách xuất Khóa khôi phục BitLocker từ Active Directory bằng PowerShell sang tệp CSV. Đi qua Active Directory và truy xuất Khóa khôi phục BitLocker là phương pháp được khuyến nghị. Bằng cách này, mọi thứ vẫn ở AD và không có hoạt động xuất khẩu nào được thực hiện. Tuy nhiên, nếu bạn cần lấy danh sách tất cả mật khẩu khôi phục BitLocker và chắc chắn đặt lại mật khẩu khôi phục sau khi đăng nhập thành công thì đây là cách tốt nhất.

Bạn có thích bài viết này không? Bạn cũng có thể thích Cách tạo báo cáo Đánh giá bảo mật Active Directory. Đừng quên theo dõi chúng tôi và chia sẻ bài viết này.

Bài viết liên quan