我有一个小的脚本,可以通过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
答案 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}}