Search code examples
powershellskype-for-business

How to add wildcard for disable accounts with PowerShell?


I have the following PowerShell command which I run to show me all the numbers that have been assigned to users. However, I'd like to narrow it down to show me ONLY accounts which have been disabled BUT still have an number assigned, I've tried a few wildcards within 'enabled' but then it fails to run.

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

Solution

  • The enabled/disabled status is encoded in the userAccountControl attribute. Try an LDAP filter like this:

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

    or collapsed:

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