News:

Ryan's Free Online Tech Forum
redux.

Main Menu

Enable Accounts

Started by scythe944, August 13, 2020, 11:35:37 AM

Previous topic - Next topic

scythe944

This is useful when you're moving a bunch of users from one domain to another, as the accounts are disabled by default (if I remember correctly).

You can then run this script on the entire OU of new users to enable them all, and assign them a password.


' Set AccountControl.vbs
' Example VBScript to enable user accounts in a named OU
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.7 - March 21st 2004
' -----------------------------------------------------------------'
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain, intCounter, intAccValue
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=SomeChildOU,OU=SomeOU,"
intAccValue = 512
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
      For each objUser in objOU
          If objUser.class="user" then
          objUser.Put "userAccountControl", intAccValue
  objUser.SetPassword "pa$$1234"
          objUser.SetInfo
          intCounter = intCounter +1
          strLastUser = objUser.Get ("name")
          End if
       next
WScript.Echo intCounter & " Accounts Enabled. Value " _
& intAccValue
WScript.Quit

'  End of VBScript Example