Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 725
  • Last Modified:

vbscript to enable all disabled users in a specific OU

dear experts!

i have a server 2003 with DC. under that DC i have an OU.
i have a bunch of disabled users that i want to enable and write the list of the disabled users to a text log file with a time stamp.

can any one help?!?!?

all the best!
0
hamzani
Asked:
hamzani
1 Solution
 
Robert SchuttSoftware EngineerCommented:
Here's a script for that, you can run it with:

cscript //nologo enable.vbs >> enable.log

Open in new window


Option Explicit

Const C_LDAP_SERVER = ""
Const C_LDAP_DOMAIN = "dc=DOMAIN,dc=local"
Const C_LDAP_OU = "TheOU"

Const C_LDAP_USR = "DOMAIN\administrator"
Const C_LDAP_PWD = "xxx"

Dim objConnection, objCommand, objRecordSet, strUser, strDN, objUser, blnDisabled
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;",C_LDAP_USR,C_LDAP_PWD

Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("SearchScope") = 2 '' ADS_SCOPE_SUBTREE

objCommand.CommandText = _
  "<LDAP://" & IIF(C_LDAP_SERVER = "", "", C_LDAP_SERVER & "/") & IIF(C_LDAP_OU = "", "", "OU=" & C_LDAP_OU & ",") & C_LDAP_DOMAIN & ">;" & _
  "(&(objectCategory=User)(userAccountControl:1.2.840.113556.1.4.803:=2));sAMAccountName,distinguishedName;OneLevel" '' or: subtree

Set objRecordSet = objCommand.Execute
While Not objRecordset.EOF
	strUser = objRecordSet.Fields("sAMAccountName").Value & ""
	strDN = objRecordSet.Fields("distinguishedName").Value & ""
	Set objUser = GetObject("LDAP://" & IIF(C_LDAP_SERVER = "", "", C_LDAP_SERVER & "/") & strDN)
	If Not objUser Is Nothing Then
		WScript.Echo Now() & " - enable account " & strUser
		''objUser.AccountDisabled = False
		''objUser.SetInfo
		Set objUser = Nothing
	End If
	objRecordset.MoveNext
Wend
objRecordset.Close
Set objRecordset = Nothing
objConnection.Close
Set objCommand.ActiveConnection = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Function IIF(a,b,c)
	If a Then IIF=b Else IIF=c
End Function

Open in new window


This is from various sources, put together. The actual enabling is not tested.
0
 
hamzaniAuthor Commented:
tnx robert!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now