Personal tools
You are here: Home Integration AD Stale Computer Record Query

AD Stale Computer Record Query

by jhysell — last modified 2008-04-09 10:47
Contributors: Beau Wells

Ever want to show your customer what computer records are stale in AD? Want to use an AD UDD discovery to distribute clients to real machines? Well here is a handy little command line that you can use to generate a file that list all machines in a domain that are stale. Stale state is determined by querying the AD database for machines that have not communicated to the Domain Controller in a specific amount of days. First example can be used to identify those records, and the second example can be used to delete those dead machines.

This query outputs a report of stale computer accounts to a CSV file without deleting them.

DSQUERY COMPUTER "OU=COMPUTERS,DC=LANDESK,DC=COM" -STALEPWD 90 -LIMIT 5000 >C:\output.csv

Command Breakdown

DSQUERY                             DSQUERY is a tool on the adminpak.msi toolset.

COMPUTER                            Specifies which type of account we are querying.

"OU=COMPUTERS,DC=LANDESK,DC=COM"    Active Directory location to query.  Children are implied.

-STALEPWD 90                        # of days that qualifies an account as stale

-LIMIT 5000                         Maximum # of lines to output.

>C:\output.csv                      Pipes results out to a CSV file called Output.csv.

This query outputs a report of stale computer accounts to a CSV file AND DELETES THEM.

DSQUERY COMPUTER "OU=COMPUTERS,DC=LANDESK,DC=COM" -STALEPWD 90 -LIMIT 5000 | DSRM -NOPROMPT >C:\Output.csv

Command Breakdown

DSQUERY                             DSQUERY is a tool on the adminpak.msi toolset.

COMPUTER                            Specifies which type of account we are querying.

"OU=COMPUTERS,DC=LANDESK,DC=COM"    Active Directory location to query.  Children are implied.

-STALEPWD 90                        # of days that qualifies an account as stale

-LIMIT 5000                         Maximum # of lines to output.

| DSRM -NOPROMPT                    Deletes computer accounts that are returned.

>C:\output.csv                      Pipes results out to a CSV file called Output.csv.



Manual page at Microsoft.

Server Says:
You humans have that emotional need to express gratitude. "You're
welcome," I believe, is the correct response.
-- Spock, "Bread and Circuses", stardate 4041.2
Safety First!
203 Days without a Dumpster fire.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: