導出 Windows LAPS 密碼報告
您想要獲取所有 Windows LAPS 密碼,以便以本地管理員身份快速登錄計算機。搜索計算機以獲取每台計算機的 Windows LAPS 密碼需要時間。雖然這是安全的最佳實踐,但有時您需要了解所有計算機及其 LAPS 密碼的概覽。這就是在 CSV 文件中包含所有 LAPS 密碼的報告的絕佳之處。在本文中,您將了解如何導出 Windows LAPS 密碼報告。
窗口圈
導出 Windows LAPS 密碼 PowerShell 腳本適用於 Windows LAPS,不適用於 Microsoft LAPS(自 2023 年 10 月 23 日起已棄用)。如果您不熟悉或想了解更多信息,請閱讀文章逐步配置 Windows LAPS。
使用 PowerShell 腳本獲取 Windows LAPS 密碼報告
Get-LAPSPasswords.ps1 PowerShell 腳本將獲取 Active Directory 中計算機對象的 Windows LAPS 密碼並輸出以下信息:
- 計算機名
- 圈數密碼
- 過期時間
- 本地管理員帳戶
- 作業系統
下載獲取 LAPSPasswords PowerShell 腳本
上創建兩個文件夾(中:)駕駛:
- 腳本
- 溫度
下載 Get-LAPSPasswords.ps1 PowerShell 腳本並將其放置在C:腳本文件夾。該腳本會將所有 LAPS 密碼導出到C:溫度文件夾。
推薦閱讀:導出 Microsoft 365 管理員角色成員報告
確保文件未被阻止,以防止運行腳本時出現錯誤。請閱讀文章運行 PowerShell 腳本時出現未數字簽名錯誤來了解更多信息。
另一種選擇是將以下代碼複製並粘貼到記事本中。給它起個名字獲取 LAPSPasswords.ps1並將其放置在C:腳本文件夾。
<#
.SYNOPSIS
Get-LAPSPasswords.ps1
.DESCRIPTION
Export Windows LAPS Passwords to CSV file with PowerShell.
.LINK
www.alitajran.com/export-windows-laps-passwords-report/
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 07/23/2024 - Initial version
#>
param (
[Parameter(Mandatory = $true)]
[string]$Path, # Mandatory parameter for the CSV file path
[string]$OU # Optional parameter to specify the OU
)
# Determine the base for the search
if ($OU) {
# If OU is provided, get computers from the specified OU
$computers = Get-ADComputer -Filter * -SearchBase $OU -Properties OperatingSystem | Select-Object Name, OperatingSystem
}
else {
# If OU is not provided, get computers from all OUs
$computers = Get-ADComputer -Filter * -Properties OperatingSystem | Select-Object Name, OperatingSystem
}
# Initialize a List to store the data
$Report = [System.Collections.Generic.List[Object]]::new()
# Loop through each computer and get the LAPS password and additional details
foreach ($computer in $computers) {
try {
# Attempt to get the LAPS password for the computer
$passwordObject = Get-LapsADPassword $computer.Name -AsPlainText
$password = $passwordObject.Password
$adminaccount = $passwordObject.Account
$expirationTimestamp = $passwordObject.ExpirationTimestamp
# Store the computer name, password, expiration timestamp, local admin account, and operating system in a custom object
$ReportLine = [PSCustomObject]@{
ComputerName = $computer.Name
LapsPassword = $password
ExpirationTime = $expirationTimestamp
LocalAdminAccount = "$adminaccount"
OperatingSystem = $computer.OperatingSystem
}
$Report.Add($ReportLine)
}
catch {
# If there's an error, output a warning
Write-Host "Failed to get details for $($computer.Name): $_" -ForegroundColor Red
}
}
# Output the results in a grid view
$Report | Sort-Object ComputerName | Out-GridView -Title LapsPasswords
# Export the results to a CSV file
$Report | Sort-Object ComputerName | Export-Csv -Path $Path -Encoding UTF8 -NoTypeInformation
這就是它的樣子。
運行獲取 LAPSPasswords PowerShell 腳本
將所有 LAPS 密碼導出到 CSV 文件。
C:scripts.Get-LAPSPasswords.ps1 -Path "C:tempLAPSPasswords.csv"
這就是網格視圖窗口中輸出的樣子。
這就是 CSV 文件的樣子。
要從 LAPS 密碼導出或者到 CSV 文件。
C:scripts.Get-LAPSPasswords.ps1 -Path "C:tempLAPSPasswordsOU.csv" -OU "OU=WIN10,OU=Computers,OU=Company,DC=exoip,DC=local"
這就是網格視圖窗口中輸出的樣子。
Windows LAPS 密碼報告看起來很棒,包含所有屬性!
結論
您了解瞭如何使用 PowerShell 導出 Windows LAPS 密碼報告。請記住在完成任務後輪換 LAPS 密碼。如果您已經設置了將在幾天內或註銷後更改 LAPS 密碼的策略,那麼一切都很好。
您喜歡這篇文章嗎?您可能還喜歡使用 PowerShell 腳本檢查 Windows 上的可用磁盤空間。不要忘記關注我們並分享這篇文章。
