delete local disabled account script

Hey everyone,

I have a server that has tons of local disabled accounts that I need to delete. I would like to automate this with a script. Can somebody provide with a script that will do this? Keep in mind that I only need the disabled accounts deleted. Thanks.
Who is Participating?
Here you go add to the IF's if there are other account exceptions you don't want deleted
strComputer = "ocnlpa-001"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
	Set objUser2 = GetObject("WinNT://" & strComputer & "/" & objUser.Name)
    If objUser2.AccountDisabled = True Then
		If objUser.Name = "Guest" Then
		Elseif objUser.Name = "HelpAssistant" Then
		Elseif InStr(objUser.Name, "SUPPORT_") > 0 Then
			colAccounts.Delete "user", objUser.Name
		End If
	End If
Wscript.Echo "Finished"

Open in new window

Vishnu KiranPrincipal Support EngineerCommented:


Please go though the below link and the steps recommended to run ascript from GPO to delete the accounts

Also visit the following link for script information for deleting users.

inurmixAuthor Commented:
Unfortanately this server is not part of a domain, its a stand-alone so GPO wont work or any script that binds to LDAP or Active Directory
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.