【问题标题】:How do I list all User Accounts with blank EmployeeID attribute from a Specific OU?如何列出特定 OU 中具有空白 EmployeeID 属性的所有用户帐户?
【发布时间】:2020-01-05 10:52:18
【问题描述】:

如何列出来自特定 OU 的所有具有空白employeeid 属性的 AD 用户帐户?

$OUpath = 'ou=users,ou=random,dc=test,dc=com'

Get-ADUser -Filter * -SearchBase $OUpath | Select-object

Get-ADUser -LDAPFilter "(!employeeID=*)" 

DistinguishedName, Name, UserPrincipalName, | Export-Csv -NoType c:\employeeID

在 line:9 char:18 + DistinguishedName,Name,UserPrincipalName | Export-Csv -NoType c:\employ ... + ~ 参数列表中缺少参数。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingArgument –

【问题讨论】:

    标签: powershell


    【解决方案1】:

    有几个问题。由于-SearchBase-LDAPFilter 可以在同一命令中使用,因此将它们结合起来将是一个好的开始。部分

    Get-ADUser -LDAPFilter "(!employeeID=*)" 
    DistinguishedName, Name, UserPrincipalName, | Export-Csv -NoType c:\employeeID
    

    意义不大。那是因为没有使用Get-ADUser -LDAPFilter "(!employeeID=*)" 的结果。也许缺少管道|?然后有一个未终止的列表DistinguishedName, Name, UserPrincipalName, |。问题是UserPrincipalName 后面的逗号。 Powershell 需要更多参数,但没有这样的东西。

    试试下面的版本:

    $OUpath = 'ou=users,ou=random,dc=test,dc=com'
    $idlessUsers = Get-ADUser -LDAPFilter "(!employeeID=*)" -SearchBase $OUpath
    $idlessUsers | select DistinguishedName, Name, UserPrincipalName | Export-Csv -NoType c:\temp\employeeID.csv
    

    【讨论】:

    • 如何添加180天未登录的查询? $OUpath = 'ou=users,ou=random,dc=test,dc=com' $CurrentDate= GET-DATE $NumberDays= 180 $idlessUsers | GET-ADUSER -filter * -SearchBase $OUpath -properties LastLogonDate |其中 { $_.LastLogonDate.AddDays($NumberDays) -lt $CurrentDate } | Disable-ADAccount $idlessUsers = Get-ADUser -LDAPFilter "(!employeeID=*)" -SearchBase $OUpath $idlessUsers |选择 samaccountname, DistinguishedName | Export-Csv -NoType c:\temp\testirun.csv
    • @Sheikku 有人会查看 AD 中的 LastLogonLastLogonTimestamp 属性。如果这个article 不够有用,请发布一个新问题。
    【解决方案2】:

    这将生成您的报告:

    $ou = "OU Path"
    Get-ADUser -Filter * -SearchBase $ou -Properties EmployeeID | Where-Object {$_.EmployeeID -like ""} | Select-Object Name,UserPrincipalName,DistinguishedName,EmployeeID | Export-Csv -NoTypeInformation -Path "C:\Temp\EID.csv"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      相关资源
      最近更新 更多