Author Posts

June 17, 2015 at 6:49 am

Hi Guys,

I am wondering if something like this can be done and can't seem to find any help googling for a situation as the one I am in.

Basically, I would need to have a script that could run in a scheduled task once per day and that takes a look at all accounts in a specific OU and if that accounts exists for more than 7 days in there, I would need to delete it. I would like to automate this process but am at a loss as to how to start.

Thanks for your input

June 17, 2015 at 6:52 am

I'd start by looking at the Get-ADUser command. It can be restricted to a specific OU (-SearchBase). You could probably apply a filter to the property containing the object's creation date and get what you want in a single query. Pipe those to Remove-ADUser, and Bob's your uncle.

June 17, 2015 at 7:44 am

I would try the below command which is in the same module as Get-ADUser to search for inactive users and pipe to Remove-ADUser for removal.

Search-ADAccount -AccountInactive -DateTime "5/16/2015"