![如何从多个域获取详细信息](https://linux22.com/image/676873/%E5%A6%82%E4%BD%95%E4%BB%8E%E5%A4%9A%E4%B8%AA%E5%9F%9F%E8%8E%B7%E5%8F%96%E8%AF%A6%E7%BB%86%E4%BF%A1%E6%81%AF.png)
我正在尝试通过 powershell 创建 html 格式的 AD 报告,但无法从多个域中获取详细信息,
下面是我的代码,
# HTML Style
$a = "<style>"
$a = $a + "BODY{background-color:SkyBlue;font-family: calibri; font-size: 10pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: grey;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
# Query Range
$dt = (get-date).adddays(-3)
# Domain Selection
$Domains = 'test1.test.com' , 'test2.testuat.com'
ForEach ($domain in $Domains) {
$report += get-aduser -Server $domain -filter 'whencreated -ge $dt' -Properties * |
# Attributes selection
select whenCreated,
SamAccountName,
GivenName,
Surname,
DisplayName,
Description,
EmployeeID,
mail,
Office,
City,
Title,
Department,
Company,
ScriptPath,
@{name=”MemberOf”;expression={$_.memberof -join “;”}}
}
$report | convertto-html -head $a | Out-File C:\scripts\ad.html
Invoke-Expression C:\scripts\ad.html
答案1
每次执行此管道时:
convertto-html -head $a | Out-File C:\scripts\ad.html
你产生一个全新的 html 文档并且文件 ( C:\scripts\ad.html
) 正在被覆盖。
用 cmdlet替换foreach(){}
循环ForEach-Object
并移动|ConvertTo-Html |Out-File
命令外部循环:
$Domains |ForEach-Object {
$Domain = $_
Get-ADUser -Server $domain -Filter {whencreated -ge $dt} -Properties * | Select-Object whenCreated # and so on.
} |ConvertTo-Html -Head $a |Out-File C:\scripts\ad.html