Home > Active Directory > How to find out inactive computers from Active Directory OU and clean them

How to find out inactive computers from Active Directory OU and clean them

How to find out inactive computers from Active Directory OU and clean them

Dsquery is a command-line tool that is built into Windows Server 2008 to find out the inactive computers or search criteria that you specify. Also we can use the dsmod and dsrm tool to disable or delete these objects at the same time.

There are two steps in this process and its explained below

Steps 1 –Find out inactive Computers from OU

Open elevated command prompt on DC and then type in

dsquery computer <distinguish name of the OU> –inactive <weeks> -limit <number> > c:computer.txt

Example

If you want to find out the 90 days inactive computers from specific OU

dsquery computer OU=TEST,DC=Ibsarabia,DC=com –inactive 12-limit500> c:computer.txt

–inactive 12: inactive in past 12 weeks (90 days)

-limit 500: limit the max entry to 500 in case there are too many objects

Steps 2 – Delete/Disable inactive computers

Pleases see below steps disable or delete these inactive objects after analyzing the computer.txt file.

To disable these objects:

type c:computer.txt | dsmod computer –disabled yes

To delete these objects:

type c:computer.txt | dsrm –noprompt -c

If you have any questions, please drop me an email

Advertisements
Categories: Active Directory
  1. here
    August 7, 2013 at 4:41 am

    Hey there! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the superb work!

  2. Ramesh
    April 17, 2014 at 4:58 pm

    Try this tool for advanced way to track the inactive users and computers

    You can manage the inactive users through this Inactive Account Tracker.

    http://www.adsysnet.com/asn-active-directory-inactive-account-tracker-download.aspx

  3. Devin
    May 15, 2014 at 7:56 am

    Nice power-shell script to find out inactive computers from AD but you can try this AD management (http://www.activedirectorymanagement.org/ ) for managing all active directory task and get report.

  4. jeff
    April 3, 2015 at 5:40 am

    thanks for blog.

    by the way, i encounter the below error message when input the command “type c:\computer.txt | dsmod computer –disabled yes”

    “dsmod failed:You must specify at least one attribute to be modified.”

  5. ITbatman
    September 2, 2015 at 11:33 am
  1. No trackbacks yet.

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

%d bloggers like this: