July 2007
S M T W T F S
« Jun   Aug »
1234567
891011121314
15161718192021
22232425262728
293031  

Google Ads

Thomas' Photography

JamiePatel ChristeningStephen at ZooKids

PowerShell Find and Delete Old Computer Accounts

   
 

I am trying to find all the inactive computer accounts in the domain. I am making a point of using PowerShell to accomplish this so I can reuse the code and I figure that I will need to learn some pretty nifty skills to accomplish this.

I am currently running this:

get-qadcomputer -sizelimit 0 -IncludedProperties CN, pwdLastSet -serialize | out-file -filepath c:\temp\computers.txt

It’s returning data in the file similar to this:

S32290 128302946226556907

S32392 128270809929026321

S32208 128302843049312152

S32234 128301846033287145

C32066 128278608138061460

E21127 128283722764262509

A55393 128297646575514617

S32364 128304029075512257

S55348 128278656649780007

C55636 128284056354353763

   
 

The number listed is the value of pwsLastSet and is described by the Microsoft Scripting Guy
“represents the number of 100 nanosecond intervals since January 1, 1601 (UTC).”

I’m dumping it to a file right now so I can make sure I have the math correct. Eventually we would like to delete any objects that have not been changed in more than 90 days, and accomplish this without dumping anything to a file – just pure PowerShell…
 

UPDATE

I found another tool – dsquery

It makes trying this in PowerShell rather silly…

Here is the command to remove any computer accounts that have been inactive more than 16 weeks

dsquery computer -inactive 16 -limit 10000 | dsrm -c -noprompt

3 comments to PowerShell Find and Delete Old Computer Accounts

  1. Mike
    September 21st, 2007 at 9:41 am

    even better: http://www.joeware.net/freetools/tools/oldcmp/index.htm

  2. Paul
    May 29th, 2009 at 4:46 pm

    As long as you have the Quest AD Cmdlets installed you can do the same in a simple one-liner using Powershell:

    get-qadcomputer -IncludeAllProperties | Where-Object { $_.lastlogon -lt (get-date).AddDays(-90) }

    Quest AD Cmdlets are free to download from http://www.quest.com/powershell/activeroles-server.aspx

  3. Remove Old Computer Accounts | Endings and Beginnings
    February 5th, 2010 at 9:30 am

    [...] Recent Comments ownbig.ru on Windows 2008 R2 ImpressionsBrown on Windows 2008 R2 ImpressionsAverill on Windows 2008 R2 ImpressionsIsabel on General UpdatesPaul on PowerShell Find and Delete Old Computer Accounts [...]

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>