Remove Disabled Users from an AD security group

Hello...

Is there a way to remove ONLY disabled users from an AD security group via VB script?

TY,
Quan
qvn7Asked:
Who is Participating?
 
RobSampsonCommented:
Did it work well enough for you to close the question?  I noticed you posted another question, I'll check it out.

Regards,

Rob.
0
 
RobSampsonCommented:
Hi, this script will remove disabled accounts from the specified Active Directory group.

Regards,

Rob.
Const ADS_UF_ACCOUNTDISABLE = 2
Set objGroup = GetObject("LDAP://CN=TestUsers,OU=TestOU,DC=Domain,DC=Com")
For Each objUser In objGroup.Members
	If objUser.Class = "user" Then
		intUAC = objUser.userAccountControl
		If intUAC And ADS_UF_ACCOUNTDISABLE Then
			WScript.Echo Mid(objUser.Name, 4) & " is disabled"
			objGroup.Remove objUser.AdsPath
			WScript.Echo Mid(objUser.Name, 4) & " was removed from " & Mid(objGroup.Name, 4)
		Else
			WScript.Echo Mid(objUser.Name, 4) & " is not disabled"
		End If
	End If
Next
MsgBox "Done"

Open in new window

0
 
qvn7Author Commented:
Thanks to those who provided great suggestions/solutions.  Appreciate it very much!!!
0
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.