A PowerShell script to help manage user and machine accounts.

Get inactive / old computer in your domain as a simple CSV.


# Gets time stamps for all computers in the domain that have NOT logged in since after specified date

import-module activedirectory

$domain = “domain.mydom.com

$DaysInactive = 90

$time = (Get-Date).Adddays(-($DaysInactive))


# Get all AD computers with lastLogonTimestamp less than our time

Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp |


# Output hostname and lastLogonTimestamp into CSV

select-object Name,@{Name=”Stamp”;

Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv OLD_Computer.csv -notypeinformation


Source:

https://gallery.technet.microsoft.com/Get-Inactive-Computer-in-54feafde

Get In Touch

Share On Social Media

Other Recent Blog Articles

Small Business HR & Payroll Made Easy (and Safeguarding Your Company from Phishing Attacks)

December 27, 2024

In this episode of Breaking Down I.T. with Steve, we welcome back Erik Swanson from Cardinal Services. Erik specializes in bringing the power of big-company HR, payroll, and benefits solutions…

Read More

Krispy Kreme Gets a Bad Taste: Cyberattack Bites into Donut Giant

December 19, 2024

Krispy Kreme Hit by Cyberattack: A Wake-Up Call for Businesses Donut lovers beware: your online Krispy Kreme orders might be on hold thanks to a recent cyberattack. The company reported…

Read More

Don’t Get Hooked: Protecting Yourself from Phishing and Spam

December 13, 2024

In this week’s episode of “Breaking Down I.T. with Steve,” we’re diving headfirst into the murky waters of unwanted emails: spam and phishing. We’ll dissect these two cyber threats, exploring…

Read More