DSQuery/DSGet for AD Computers

Basically i'm trying to return a list of inactive computer accounts.

I can do that with dsquery but I also want it to show me how many days the machine has been inactive.  How can I do that?

May 20th, 2013 2:35pm

The only way to do it is via script?  I was trying to find an attribute that would return either the number of days its been since the machine checked in with the domain or the last actual date that it did.
May 20th, 2013 3:45pm

Well, you're asking this question in a scripting forum so...

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2013 3:51pm

The -Inactive parameter of dsquery computer can retrieve computers that have been inactive for a specified number of weeks. It uses the lastLogonTimeStamp attribute to determine how long computers have been inactive. However, lastLogonTimeStamp is a large (64-bit) integer representing dates as the number of 100-nanosecond intervals since 12:00 am, January 1, 1601 in UTC. The dsquery utility uses code to convert this large number into a datetime in the local time zone and calculate the number of weeks in the past. There is no provision for dsget/dsquery to output the number of weeks. The best you could do would be to use dsquery computer -Inactive to retrieve the DN of stale computers, then pipe this to dsquery * and use the -Attr parameter to output the value of lastLogonTimeStamp. But this would output the large integer, not the corresponding date/time, much less the number of weeks in the past. You would need to use a VBScript or PowerShell script to output the number of weeks.

May 20th, 2013 3:57pm

That is exactly what I've started trying to do.

Thanks.

This is what I came up with - dsquery computer "OU=computers,DC=Me,DC=Com" -o samid -inactive 16 - limit 10000 |dsquery computer -attr SAMAccountName lastLogonTimeStamp | export-csv C:\users\me\desktop\inactive.csv.

When I try this, I get dsqyery failed attr is an unknown parameter.

But also i thought I needed to pipe the results to show the last logon, but am I supposed to call dsquery twice?

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2013 4:14pm

I didn't mean it in that way, I just wanted to really know if I could take a simpler one-liner maybe to reach the same results as some of the scripts goy.
May 20th, 2013 4:15pm

You use the -Attr parameter with dsquery * rather than dsquery computer. Just replace "computer" with "*".

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2013 4:27pm

The following command will return a list of computer objects inactive for the previous 12 weeks. 

dsquery computer -inactive 12 -limit 2000 >c:\inactive12.txt

Hope this helps,

Mike


April 13th, 2015 2:20pm

Search-ADAccount is probably the preferred method moving forward.
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2015 2:25pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics