Get Enabled or Disabled Computer Accounts

Here’s a quick workaround for the lack of -Enabled switch for Get-QADComputer. Unlike Get-QADUser it does not currently have the switch, however, so these two oneliners will come handy should you want to efficiently filter computers by their enabled/disabled status:

# Only disabled computer accounts
Get-QADComputer -ldapFilter (userAccountControl:1.2.840.113556.1.4.803:=2)

# Only enabled computer accounts
Get-QADComputer -ldapFilter (!(userAccountControl:1.2.840.113556.1.4.803:=2))

10 Responses to “Get Enabled or Disabled Computer Accounts”


  1. 1 Craig April 12, 2010 at 5:27 pm

    I was just looking for this feature last week and I ended up using: get-qadcomputer | where-object {$_.accountisdisabled -eq $True}

    • 2 Dmitry Sotnikov April 12, 2010 at 6:59 pm

      where-object obviously works as well – but it is sway slower because the filtering is happening on the client side after all the records are retrieved. Server-side is more effivient.

  2. 3 Rick Sheikh April 13, 2010 at 4:00 pm

    Server-side would be more efficient also if you could do this,

    (Get-QADComputer -sl 0).accountisdisabled -eq $true

  3. 4 Clint B April 17, 2010 at 3:54 pm

    That is pure LDAP gold. I did a quick search for more LDAP bitwise queries and found http://support.microsoft.com/kb/269181. Those OIDs are worth saving somewhere🙂 Thanks, Dmitry!

  4. 6 Luke April 22, 2010 at 5:33 pm

    Hi Dimitry,

    Can you explain why Get-QADObject is so much faster?

    PS Scripts:\> Measure-Command {Get-QADComputer -ldapFilter `(userAccountControl:1.2.840.113556.1.4.803:=2)’}

    Days : 0
    Hours : 0
    Minutes : 0
    Seconds : 6
    Milliseconds : 63
    Ticks : 60635169
    TotalDays : 7.017959375E-05
    TotalHours : 0.00168431025
    TotalMinutes : 0.101058615
    TotalSeconds : 6.0635169
    TotalMilliseconds : 6063.5169

    PS Scripts:\> Measure-Command {Get-QADObject -ldapFilter `(&(objectclass=computer)(userAccountControl:1.2.840.113556.1.4.803:=2))’}

    Days : 0
    Hours : 0
    Minutes : 0
    Seconds : 2
    Milliseconds : 644
    Ticks : 26448893
    TotalDays : 3.06121446759259E-05
    TotalHours : 0.000734691472222222
    TotalMinutes : 0.0440814883333333
    TotalSeconds : 2.6448893
    TotalMilliseconds : 2644.8893

  5. 7 John January 15, 2013 at 9:09 pm

    how about list all computers on AD locating “OU=Chicago,OU=Test,DC=Test,DC=com” that are inactive for 1 week?

  6. 8 sadheesh June 26, 2013 at 6:38 pm

    thanks Dmitry Sotnikov, this script helps me.

  7. 9 Anonymous August 24, 2016 at 4:21 am

    Get-ADComputer -Filter “Enabled -eq ‘$false'” | Select Name

  8. 10 Anonymous September 14, 2016 at 1:47 am

    Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} | Where {$_.Enabled -eq $true}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

April 2010
M T W T F S S
« Mar   May »
 1234
567891011
12131415161718
19202122232425
2627282930  

%d bloggers like this: