Solved

Remove Disabled Users from an AD security group

Posted on 2011-03-16
4
1,179 Views
Last Modified: 2012-05-11
Hello...

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

TY,
Quan
0
Comment
Question by:qvn7
  • 2
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 35153895
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
 

Author Comment

by:qvn7
ID: 35156818
Thanks to those who provided great suggestions/solutions.  Appreciate it very much!!!
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35162338
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Resolve DNS query failed errors for Exchange
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now