我是PowerShell新手。
我正在尝试创build一个显示即将到期的AD帐户的报告。
报告应该包括用户名,AccountExpirationDate和经理。
到目前为止,我有以下几点:
$users = Search-ADAccount -AccountExpiring -TimeSpan "7" | Select-Object Name,AccountExpirationDate | Sort-Object AccountExpirationDate $manager = Search-ADAccount -AccountExpiring -TimeSpan "7" | Get-aduser -Properties Manager | Select-Object @{n="ManagerName";e={(Get-ADUser -Identity $_.Manager -Properties displayName).DisplayName}}
无论如何,我可以将结果合并到一张表中吗?
懒惰,只需获得第一次通过的Manager属性,并通过pipe道把它变成你的计算属性。
Search-ADAccount -AccountExpiring -TimeSpan "7" | Get-ADUser -Properties Name, AccountExpirationDate, Manager | Select-Object Name, AccountExpirationDate, @{ name = 'Manager'; expression = { (Get-ADuser $_.Manager -Properties displayName).displayName } } | Sort-Object AccountExpirationDate