Powershell: Get Inactive Computer objects in AD
I made a new Powershell script to retrieve all inactive and “non used” computer accounts for a specific organizational unit in Active Directory. You need to use the attribute “lastLogonTimestamp” from AD like you can see in the screenshot below. There is also a “lastlogon” attribute present but this an old attribute which is not replicated among the domain controllers. This attribute is only updated on the domain controller you are currently using therefor we use “lastLogonTimestamp” which is replicated. I have also used the Quest Active Roles which is free to download.
The script below will display first the inactive computer objects that not have been signed-in in the last 3 Months, afterward are the “never used” computer accounts displayed. Modify the $Days & $OU variable to change the number of inactive days and the specified Organizational unit.
Script:
#Display inactive and "non used" workstations of a specific Organizational Unit #More info: https://jthys.wordpress.com cls $Currentdate = get-date $Days = 90 $OU = "RSRC.int/Managed Computers" $inactive = Get-QADComputer -SearchRoot $OU -SizeLimit 0 -IncludedProperties LastLogonTimeStamp | where { $_.LastLogonTimeStamp -ne $null -and ($Currentdate-$_.LastLogonTimeStamp).Days -gt $Days } $neverused = Get-QADComputer -SearchRoot $OU -SizeLimit 0 -IncludedProperties LastLogonTimeStamp | where { $_.LastLogonTimeStamp -eq $null } Write-Host "Inactive Workstations:" $inactive | format-table name, lastlogonTimeStamp -autosize write-host "Never used Worksations:" $neverused | format-table name -autosize
Output:
note: I have changed the variable $days to 5 to generate some output on my test domain controller.
Thank you, this is what I need. But it doesn’t work in my PC “<b style="color:black;background-color:#99ff99"……….“. So I excluded that strings from lines 7,9,12,13.
Hello just wanted to give you a quick heads up.
The text in your post seem to be running off the screen in Safari.
I’m not sure if this is a format issue or something to do with browser compatibility but I thought I’d post to let you know.
The style and design look great though! Hope you get the problem
resolved soon. Thanks
Very good article. I will be experiencing many of these issues as well.
.
Excellent. To be sure.
Hey! I know this is kinda off topic but I was wondering which blog platform are you using for this
site? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.
Just wordpress.com site.
not the wordpress.org which you need to host by yourself or someonelse.
This is the perfect site for anybody who would like to understand this topic.
You understand a whole lot its almost tough to argue with you (not
that I really would want to…HaHa). You definitely put a
fresh spin on a subject that has been discussed for decades.
Great stuff, just wonderful!
I like the valuable info you provide in your articles. I will bookmark your weblog and check again
here regularly. I’m quite sure I’ll learn plenty of
new stuff right here! Good luck for the next!
Hey, I think your site might be having browser compatibility issues.
When I look at your blog site in Opera, it looks fine but when
opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up!
Other then that, fantastic blog!
You can definitely see your skills within the article you
write. The sector hopes for more passionate writers like you who aren’t afraid to say how they believe. All the time go after your heart.
Will there be an RSS feed that we may sign up for on
this site so if you have new content that we could be notified?
Nice post. I was checking constantly this blog and I’m impressed! Very helpful info specially the last part 🙂 I care for such info much. I was looking for this particular information for a very long time. Thank you and best of luck.