Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This prints disabled computer accounts to the screen. I want to run a conditional statement against the results and, if true, move them to my "disabled" OU.

get-adcomputer -ldapfilter "(&(objectCategory=computer)(objectClass=computer)(useraccountcontrol:1.2.840.113556.1.4.803:=2))"|select Name, enabled
share|improve this question
Not sure what you mean by the whole "conditional statement" part, so I ignored it in my answer. – Chris S Sep 24 '13 at 14:34
up vote 2 down vote accepted
Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(objectClass=computer)(useraccountcontrol:1.2.840.113556.1.4.803:=2))" | Move-ADObject -TargetPath "OU=disabled,DC=ad,DC=example,DC=net"

Note: This will catch all the computers currently in the OU. You'd need to limit the scope of the search to filter them out otherwise it will retry the move (I'm not sure if it'll fail for those computers, or just skip them)

TheCleaner also wanted me to mention that you can add a -Filter {(DistinguishedName -notlike "OU=disabled,DC=ad,DC=example,DC=net")} to that Get-ADComputer statement to filter out the already moved computer.

share|improve this answer
works for me, thanks. – user179037 Sep 24 '13 at 14:47

It is easy to do this through Active Directory Users and Computers GUI. You can view all the disabled computers and then select all and move to the needed OU.

To achieve it, you just need to create a Saved Query in Active Directory Users and Computers, Saved queries -> right click -> New -> query -> Click Define query -> Select Custom Search mode -> Advanced -> paste the following query.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.