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

3 years, 10 months ago.

  • Author
  • #26566

    Topics: 1
    Replies: 0
    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    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

    Topics: 2
    Replies: 525
    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort