如何使用 PowerShell 添加通配符以禁用帐户?

How to add wildcard for disable accounts with PowerShell?

我有以下 PowerShell 命令,我 运行 向我显示已分配给用户的所有号码。但是,我想缩小范围以仅显示已禁用但仍分配了号码的帐户,我在 'enabled' 中尝试了一些通配符,但后来失败了 运行。

Get-ADUser -Properties "msRTCSIP-Line",mail,l,c,Enabled,CanonicalName -LDAPFilter "(msRTCSIP-Line=tel:+44*)" |
    Select Name,CanonicalName,mail,l,c,Enabled,"msRTCSIP-Line" |
    ft -AutoSize

enabled/disabled 状态编码在 userAccountControl 属性中。试试这样的 LDAP 过滤器:

(&
    (objectclass=user)
    (objectcategory=user)
    (useraccountcontrol:1.2.840.113556.1.4.803:=2)
    (msRTCSIP-Line=tel:*)
)

或崩溃:

(&(objectclass=user)(objectcategory=user)(useraccountcontrol:1.2.840.113556.1.4.803:=2)(msRTCSIP-Line=tel:*))

我认为最好的方法是获取所有禁用的帐户,然后将其通过管道传输到您的代码中:

Search-ADAccount -AccountDisabled -UsersOnly | %{
    Get-ADUser $_ -Properties "msRTCSIP-Line",mail,l,c,Enabled,CanonicalName -LDAPFilter "(msRTCSIP-Line=tel:+44*)" | 
    Select Name,CanonicalName,mail,l,c,Enabled,"msRTCSIP-Line"
}