我的列表是员工编号,但如果我的列表上的一些数字不在Active Directory中,则在结果中这些id被绕过,因此我不知道这是一个不正确的数字。我能让坏id也显示在我的名单上吗?
Get-Content c:tempdisable.txt | ForEach-Object {
Get-ADUser -LDAPFilter "(samaccountname=$_)" |
Select-Object -Property samaccountname,surname,givenname,enabled
}
如果查询没有产生结果,请自己创建一个对象:
Get-Content c:tempdisable.txt | ForEach-Object {
$user = Get-ADUser -LDAPFilter "(samaccountname=$_)" |
Select-Object -Property samaccountname,surname,givenname,enabled
if ($user) {
$user
} else {
New-Object -Type PSObject -Property @{
samaccountname = $_
surname = ''
givenname = ''
enabled = $null
}
}
}