DSQUERY

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
pjones
Posts: 2
Joined: Wed May 05, 2010 2:08 am

DSQUERY

Post by pjones » Wed May 05, 2010 2:10 am

I am trying to automate the cleanout of stale records from AD.

Here is the query set I have so far.

dsquery * -filter "&(objectCategory=group)(!member=*)" -limit 0 > "C:DSQUERYADGROUPSemptygrp.txt"dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(userAccountControl:1.2.840.113556.1.4.803:=32))" -limit 0 > "C:DSQUERYADUSERSnopwd.txt"dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(userAccountControl:1.2.840.113556.1.4.803:=65536))" -limit 0 > "C:DSQUERYADUSERSnoexpire.txt"dsquery user domainroot -stalepwd 90 -limit 0 > "C:DSQUERYADUSERSstaleusr.txt"dsquery user domainroot -inactive 13 -limit 0 > "C:DSQUERYADUSERSinacuser.txt"dsquery computer -inactive 13 -limit 0 > "C:DSQUERYADCOMPUTERSinaccomp.txt"dsquery computer -stalepwd 90 -limit 0 > "C:DSQUERYADCOMPUTERSstalcomp.txt"

What I would like to be able to do is omit Disabled objects from the results. Is there any way to do this?

jvierra
Posts: 13953
Joined: Tue May 22, 2007 9:57 am
Contact:

DSQUERY

Post by jvierra » Wed May 05, 2010 3:07 am

The following query returns everything that does not have this atribvute set or that does not have this attribute defined.
(&(!userAccountControl:1.2.840.113556.1.4.803:=2))

Code: Select all

	
dsquery * -filter "(&(!userAccountControl:1.2.840.113556.1.4.803:=2))"
	

jvierra
Posts: 13953
Joined: Tue May 22, 2007 9:57 am
Contact:

DSQUERY

Post by jvierra » Wed May 05, 2010 3:26 am

Code: Select all

	
dsquery * -filter "(&(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=2)))" | dsquery computer -inactive 1
	
 
	
dsquery * -filter "(&(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=2)))" |dsquery computer -stalepwd 90 -limit 0 
	
 
	

The cascade can only be done in this order.


jvierra
Posts: 13953
Joined: Tue May 22, 2007 9:57 am
Contact:

DSQUERY

Post by jvierra » Thu May 06, 2010 2:08 am

DisabledStale %date%
with no quotes should work

User avatar
pjones
Posts: 2
Joined: Wed May 05, 2010 2:08 am

DSQUERY

Post by pjones » Thu May 06, 2010 3:06 am

Nope, dsmod failed: 06/05/2010 is an unknown parameter.

Locked