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

Phishing Scams: The Sneaky Threat Lurking in Portland’s Small Businesses – How PDX IT Services Can Help

June 4, 2025

In the bustling small business landscape of Portland, Oregon, every entrepreneur is focused on growth, innovation, and serving their community. But lurking in the shadows, a persistent and increasingly sophisticated…

Read More

From “Oh No!” to “We Got This!”: Navigating Business Continuity & Disaster Recovery

May 29, 2025

Business Continuity vs. Disaster Recovery: A Holistic View At its core, Disaster Recovery (DR) is a subset of Business Continuity (BC). Think of BC as the overarching strategy that ensures…

Read More

5 Cybersecurity Tips for Small Businesses

May 29, 2025

In today’s digital age, cyber threats are a constant concern for businesses of all sizes. Small businesses, often with limited resources, can be particularly vulnerable. A single data breach can…

Read More