Delete AD user who is inactive for x amount of time

 

 

                                https://flashstart.com/wp-content/uploads/2022/04/fs_sito_img_activedirectory-page.png 

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