Search-ADAccount未返回EmployeeID / EmployeeNumber

时间:2019-06-12 12:04:14

标签: powershell

我有一个小的脚本,可以通过AD查找并找到用户的EmployeeID号。但是,Search-ADAccount为所有用户返回EmployeeID / EmployeeNumber的空白值。

这是我的代码:

$expiredaccounts = Search-ADAccount -AccountExpiring -TimeSpan 30.00:00:00 | Where-Object { $_.Enabled -eq $true } | Select-Object name, SamAccountName, AccountExpirationDate, EmployeeID|  ConvertTo-Html | Out-String

Send-MailMessage -to $emailto -Subject $subject -SmtpServer $smtp -From $fromaddress -Cc $emailcc -Body ($expiredaccounts) -BodyAsHtml

1 个答案:

答案 0 :(得分:2)

Search-ADAccount不在其结果集中返回employeeID属性,不幸的是不支持指定额外的属性。

您可以通过在计算所得的属性中单独调用employeeID来获取Get-ADUser值:

$expiredaccounts = Search-ADAccount -AccountExpiring -TimeSpan 30.00:00:00 | Where-Object { $_.Enabled -eq $true } 
$expiredaccounts | Select-Object name, SamAccountName, AccountExpirationDate, @{Name='EmployeeID';Expression={($_ |Get-ADUser -Properties employeeID).employeeID}}