Powershell 脚本,用于提取 OU 中最新 Bitlocker 恢复密钥早于指定日期的所有计算机

问题描述 投票:0回答:1
我正在尝试编写一个执行上述任务的脚本。 具体来说,我希望提取计算机名称和恢复密钥日期的列表,但前提是最新的恢复密钥是在特定日期之前创建的。

我在变量 $computers 中有来自 OU 的计算机列表。

到目前为止,我正在使用以下代码,并且每台计算机都收到“获取“在此处插入计算机名称”的恢复信息时出错:未找到目录对象”。 即使它成功地从对象中提取了可分辨名称,所以我不确定为什么它会说“找不到目录对象”。

Error Message Screenshot

foreach ($computer in $computers) { Write-Output "Processing computer: $computer" try { $computerObject = Get-ADComputer -Identity $computer -Server "yourdomain.com" $computerDN = $computerObject.DistinguishedName Write-Output "Computer DistinguishedName: $computerDN" $recoveryKeys = Get-ADObject -Filter { objectClass -eq "msFVE-RecoveryInformation" } -SearchBase "CN=Microsoft BitLocker Drive Encryption Recovery Information,$computerDN" -Properties WhenCreated, msFVE-RecoveryPassword if ($recoveryKeys) { $latestKey = $recoveryKeys | Sort-Object WhenCreated -Descending | Select-Object -First 1 if ($latestKey.WhenCreated -lt $date) { Write-Output "Computer: $computer" Write-Output "Recovery Key Created: $($latestKey.WhenCreated)" Write-Output "Recovery Key: $($latestKey.'msFVE-RecoveryPassword')" } else { Write-Output "No recovery keys newer than $date found for $computer" } } else { Write-Output "No recovery keys found for $computer" } } catch { Write-Output ("Error fetching recovery information for ${computer}: " + $_.Exception.Message) } }
    
powershell active-directory bitlocker
1个回答
0
投票

https://www.reddit.com/r/PowerShell/comments/8bj4il/powershell_to_pull_bitlocker_recovery_most_recent/

这解决了我的问题。 很棒的剧本!

© www.soinside.com 2019 - 2024. All rights reserved.