<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Hey, Scripting Guy! How Can I Find Old Computer Accounts?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2008/11/19/how-can-i-find-old-computer-accounts.aspx</link><description>Hey, Scripting Guy! We have had a number of changes at our company recently. As a result, our Active Directory Domain Services (AD DS) installation is somewhat shabby. Okay, a lot shabby. When I go into AD DS Users and Computers and look through it, I</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Hey, Scripting Guy! How Can I Find Old Computer Accounts?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2008/11/19/how-can-i-find-old-computer-accounts.aspx#3283878</link><pubDate>Tue, 29 Sep 2009 21:05:19 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3283878</guid><dc:creator>ScriptingGuy1</dc:creator><description>&lt;p&gt;Thanks for the comment, I have updated the code.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3283878" width="1" height="1"&gt;</description></item><item><title>Did you test this code?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2008/11/19/how-can-i-find-old-computer-accounts.aspx#3269836</link><pubDate>Fri, 31 Jul 2009 19:23:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3269836</guid><dc:creator>cking2</dc:creator><description>&lt;p&gt;Really? Were you underwater when you wrote this or is it a test?&lt;/p&gt;
&lt;p&gt;incorrect syntax, missing Writes, datemath issues...? &lt;/p&gt;
&lt;p&gt;I am trying to learn Powershell and you actually did me a favor while I tried to figure out if I am stupid or the snippet was full of holes.&lt;/p&gt;
&lt;p&gt;$maxOldLogonDays = 60&lt;/p&gt;
&lt;p&gt;$query = New-Object system.directoryservices.directorysearcher&lt;/p&gt;
&lt;p&gt;$root = [adsi]&amp;quot;LDAP://-your path-,DC=COM&amp;quot;&lt;/p&gt;
&lt;p&gt;$query.SearchRoot = $root&lt;/p&gt;
&lt;p&gt;$query.filter = &amp;quot;(objectCategory=computer)&amp;quot;&lt;/p&gt;
&lt;p&gt;$query.SearchScope = &amp;quot;subtree&amp;quot;&lt;/p&gt;
&lt;p&gt;$result = $query.findAll() |&lt;/p&gt;
&lt;p&gt;ForEach-Object	-process `&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	if ($_.properties.item(&amp;quot;lastlogon&amp;quot;) -gt 0) &lt;/p&gt;
&lt;p&gt;	#I get alot of lastlogons that are not null but not empty either&lt;/p&gt;
&lt;p&gt;	#-gt 0 seems to work best as test for valid datestamp&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		$rawLogon = $_.properties.item(&amp;quot;lastlogon&amp;quot;)&lt;/p&gt;
&lt;p&gt;		$convertedLogOn = [datetime]::FromFileTime([int64]::Parse($rawLogon))&lt;/p&gt;
&lt;p&gt;		Write-Host $convertedLogOn&lt;/p&gt;
&lt;p&gt;		$passwordage = ((get-date) - $convertedLogOn)&lt;/p&gt;
&lt;p&gt;		Write-Host $passwordage.Days&lt;/p&gt;
&lt;p&gt;		If($passwordage.Days -gt $maxOldLogonDays)&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			Write-Host &amp;quot;$($_.properties.item('distinguishedName')) &lt;/p&gt;
&lt;p&gt;			has not logged on for more than &amp;nbsp;$maxOldLogonDays days&amp;quot; &lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3269836" width="1" height="1"&gt;</description></item></channel></rss>