Powershell Script : Find and delete AD users that are Disabled since xx days

Posted on 2014-08-07
Last Modified: 2014-09-02
Hi Experts,

we need to Find and Delete AD users that are Disabled since xx days.

Thanks in Advance !
Question by:Santosh Gupta
    LVL 28

    Accepted Solution

    $time = (Get-Date).Adddays(-(60) 
    Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -ne $true} | % {Remove-ADUser -Identity $_.samaccountname -whatif }

    Open in new window

    I used last logon timestamp to validate last time the user logged in, however this is no guarantee on "disabled date"

    The previously answered question below should also give you some context on disabled date:
    LVL 28

    Expert Comment

    Do you need any further help with this ?

    Are there any errors with the script provided or any additional concerns ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now