There is apparently a way to delete accounts on systems that haven’t been used in over 30 days with an AD Group Policy setting. I found that this GP setting did not work on the Windows 10 systems I manage. Also, even if it did work, there are a few accounts on these systems that I do not want deleted even if they haven’t been used in months. Therefore, I came up with a powershell script based on many other people’s work that deletes user accounts and profiles that haven’t been used in over 30 days.
Download powershell script to delete 30 day unused user accounts and user profiles
Before running this script on your systems, edit it with a script editor to review the details within the script!!!
To run this script, I also recommend you open an administrative command prompt and give the commands:
cd c:\users
dir /od /ta
This will give you a sorted list of the accounts and the last time the account profile was accessed. You can compare that list to the accounts that will be deleted when running the script. Note that if the list of users to delete is long, you may get quota violations when running the script. When this happens I reboot and run the script again.
To run the script open a powershell window with “run as administrator” and run the script from whatever directory you have saved it in. When running the script be sure to check the list of accounts about to be deleted for any accounts you don’t want to delete. If you see any, you can exit the script as instructed and then edit the script to add the accounts you don’t want deleted to the line indicated in the script.
——————————-
On the windows systems I manage I have already pre-loaded my private version of the script in a specific folder so the steps to run this are:
- 1) Login with the lab administrator account
- 2) Open a Powershell command window “Run as Administrator” (click on the magnifying glass in the bottom left, type Powershell, Right-click on the PowerShell App and select “Run as administrator” …)
- 3) Give the following three commands:
set-executionpolicy unrestricted
C:\williams\DeleteOldUsers.ps1
set-executionpolicy undefined