Powershell script to automatically remove inactive users.

Welcome Forums General PowerShell Q&A Powershell script to automatically remove inactive users.

This topic contains 2 replies, has 3 voices, and was last updated by

 
Moderator
3 years, 6 months ago.

  • Author
    Posts
  • #26566

    Participant
    Points: 0
    Rank: Member

    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

  • #26568

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #26570

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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"

The topic ‘Powershell script to automatically remove inactive users.’ is closed to new replies.