Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2014-08-07
2
Medium Priority
?
324 Views
Last Modified: 2014-09-02
Hi Experts,

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

Thanks in Advance !
0
Comment
Question by:Santosh Gupta
  • 2
2 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 40246995
$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:
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27514580.html
0
 
LVL 29

Expert Comment

by:becraig
ID: 40261171
Do you need any further help with this ?

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

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

578 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