我想通过PowerShell创buildAD报告,但无法从多个域获取详细信息,
下面是我的代码,
# 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)) { 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 “;”}}| convertto-html -head $a | Out-File C:\scripts\ad.html } Invoke-Expression C:\scripts\ad.html
每当这个pipe道被执行时:
convertto-html -head $a | Out-File C:\scripts\ad.html
你生成一个全新的html文件 ,并且文件( C:\scripts\ad.html )被覆盖。
用ForEach-Object cmdletreplaceforeach(){}循环,并将|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