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

Digital Vigilance: Fortifying Your Defenses in the Face of Cyber Threats

February 28, 2024

Welcome to this episode where we plunge deep into the intricate realm of hacking, arming you with indispensable knowledge on the necessary actions to undertake upon uncovering a security breach.…

Read More

Empowering Tech Resilience: Navigating Surge Protection and Uninterruptible Power Supplies with Steve!

February 21, 2024

Greetings and welcome to Breaking Down I.T. with Steve, the ultimate podcast destination where we unravel the intricacies of technology. In this latest episode, we embark on a journey to…

Read More

Understanding Proactive IT Strategies for Small Businesses

February 21, 2024

Proactive IT strategies for small businesses are about staying ahead of problems before they hit. Think of it like this, you wouldn’t wait for a leak to flood your house…

Read More