Delete AD user who is inactive for x amount of time
In this blog post, I'll show you how to delete inactive members from Windows Active Directory after 30 days of activity.
The amount of days is completely customizable. This works in any version of windows server.
For test, let us take the following user account
This is a user profile of the AD user.
User spantosh@surya.local
Has was last logged in 28th August 2022
This is AD Computer profile
Now
Removing AD Computer
Set time variable
$time = (Get-Date).Adddays(-($30))
this will get the time of computers that are inactive for 30 days
Get-ADComputer -Filter {lastlogontimestamp -lt $time} -Properties Name
Comments
Post a Comment