如何从多个域获取详细信息

如何从多个域获取详细信息

我正在尝试通过 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

相关内容