Thanks for the quick reply bluntTony, but the command "dsquery user -disabled -limit 0 > dis.txt" at the top of the batch file should output all disabled user's to the text file that is used by the next line down and so I should not need to enter the user's manually as far as I am aware. My only reason for looking at DOS rather than VB was because my VB skills are quite limited and whilst I would expect your script to work fine making changes to it if needed will not be as easy for me. I will however try it out on some of the older OU's that we have setup for accounts that have been disabled for a couple of years and hence don't matter too much.
Main Topics
Browse All Topics





by: bluntTonyPosted on 2009-11-04 at 08:43:25ID: 25741191
The problem with that batch is that you have to type all the disabled accounts into the txt file before running it.
The below VBScript will search your entire domain for all disbaled accounts, and remove any groups it is a member of. Bear in mind this will NOT remove the primary group (Domain Users) by default as the user needs to have at least one primary group. If your primary group is not Domain Users and you want to switch it to this then this will require further coding.
Run the script via cscript, e.g.
cscript myscript.vbs
...to output a list of the users and groups which will be affected. When you're happy, run it with the following switch:
cscript myscript.vbs /forreal:Y
...this will actually remove the group memberships.
Something as potentially destructive as this I always test first!
Tony
Select allOpen in new window