Ray - Systems Administrator
  • Home
  • About
  • Skills
  • Experience
  • Education
  • Projects
  • Blog
  • Contact
  • Dark Theme
    Light Theme Dark Theme System Theme
  • Tags
  • About
  • Active Directory
  • AI
  • Automation
  • Hugo
  • Infrastructure
  • Intro
  • IT Operations
  • JavaScript
  • Monitoring
  • Performance
  • Portfolio
  • PowerShell
  • Scripting
  • Security
  • Static Site
  • Trends
  • Tutorial
  • Web Development
  • Welcome
Hero Image
Active Directory Cleanup Automation with PowerShell

Introduction Stale and unused objects in Active Directory not only clutter your environment but can also create security risks and provisioning errors. Automating cleanup ensures better hygiene and consistent identity lifecycle management. This guide walks through how to use PowerShell to audit and optionally remove inactive AD users and computers. Core Principles 1. Identify Inactive Users and Computers # Users inactive for 90+ days $inactiveUsers = Get-ADUser -Filter * -Properties LastLogonDate | Where-Object { $_.Enabled -eq $true -and $_.LastLogonDate -lt (Get-Date).AddDays(-90) } # Computers inactive for 90+ days $inactiveComputers = Get-ADComputer -Filter * -Properties LastLogonDate | Where-Object { $_.Enabled -eq $true -and $_.LastLogonDate -lt (Get-Date).AddDays(-90) } 🔍 Use -SearchBase to narrow to a specific OU Example: -SearchBase "OU=Workstations,DC=corp,DC=domain,DC=com"

  • PowerShell
  • Active Directory
  • Automation
  • Security
  • IT Operations
Monday, March 18, 2024 | 2 minutes Read
Navigation
  • About
  • Skills
  • Experience
  • Projects
  • Blog
Contact me:
  • [email protected]
  • Location: New York, Ny
  • Website: https://200rx.com

Toha Theme Logo
© 2025 Copyright.
Powered by Hugo Logo