+ Post New Thread
Results 1 to 5 of 5
Windows 7 Thread, Staff - Bulk enable \ disable all accounts in one OU in Technical; Evening all, I have been asked to set up some accounts with additional privileges for our computing students which is ...
  1. #1
    eddyc's Avatar
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    438
    Thank Post
    99
    Thanked 47 Times in 43 Posts
    Rep Power
    22

    Staff - Bulk enable \ disable all accounts in one OU

    Evening all,

    I have been asked to set up some accounts with additional privileges for our computing students which is fine as the ICT Curriculum Area have agreed that these accounts will be disabled, and enabled as required by themselves.
    I'm going to put all of the accounts within one OU and delegate control but do not want to install the AD toolkit on any machines.
    Can I set up a batch file somewhere in a shared drive to enable \ disable the accounts? and does anyone know what I need to put in the batch file.
    I have Googled but not had much joy to date.

    Thanks, Ed

  2. #2
    rob_coles's Avatar
    Join Date
    Mar 2007
    Location
    Hull
    Posts
    109
    Thank Post
    16
    Thanked 14 Times in 10 Posts
    Rep Power
    18

  3. #3
    eddyc's Avatar
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    438
    Thank Post
    99
    Thanked 47 Times in 43 Posts
    Rep Power
    22
    Quote Originally Posted by rob_coles View Post
    Sadly that will only let them enable and disable one account at a time, I ideally need a batch file which will do the whole OU in one hit. Thanks anyway though.

  4. #4

    Join Date
    Feb 2012
    Location
    Durham
    Posts
    52
    Thank Post
    5
    Thanked 8 Times in 4 Posts
    Rep Power
    7
    The below might work for you.

    You will need to change lines 17 and 25 to your AD config. Save the file as enable accounts then change line 28 to say
    objUser.AccountDisabled = True
    and save it as disable account.

    Hope this is what you are looking for.

    'On Error Resume Next

    ' Set veriables
    Const ADS_SCOPE_SUBTREE = 2
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    'set query limit to 1000 records
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

    'Get all users from Systems Services test OU
    objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://PLUTO/ou=test,ou=Systems Services,dc=hummersknott,dc=local' WHERE objectCategory='user'"
    Set objRecordSet = objCommand.Execute

    'Loop through all users
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF

    'set ldap query with name from above query
    Set objUser = GetObject("LDAP://PLUTO/cn="& objRecordSet.Fields("Name").Value &",ou=test,ou=Systems Services,dc=hummersknott,dc=local")

    'Enable Account
    objUser.AccountDisabled = False

    'Write changes to active directory account
    objUser.SetInfo

    'Wscript.Echo objRecordSet.Fields("Name").Value

    'move onto next account
    objRecordSet.MoveNext
    Loop

    msgbox("Done")

  5. Thanks to nev104 from:

    eddyc (16th December 2013)

  6. #5
    eddyc's Avatar
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    438
    Thank Post
    99
    Thanked 47 Times in 43 Posts
    Rep Power
    22
    Thanks so much for that! It does exactly what is needed. :-)

    Quote Originally Posted by nev104 View Post
    The below might work for you.

    You will need to change lines 17 and 25 to your AD config. Save the file as enable accounts then change line 28 to say and save it as disable account.

    Hope this is what you are looking for.

SHARE:
+ Post New Thread

Similar Threads

  1. [SCCM 2007] SCCM - Can it look after a part of a domain (as in one OU?)
    By garethedmondson in forum O/S Deployment
    Replies: 4
    Last Post: 24th March 2011, 10:52 PM
  2. Autamatic Disable of Accounts in AD
    By Garyd53 in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 6th October 2009, 09:07 AM
  3. Replies: 9
    Last Post: 12th September 2008, 08:53 AM
  4. Issues with new user accounts in an OU
    By Scruff in forum Windows
    Replies: 0
    Last Post: 7th September 2007, 10:12 AM
  5. Set all Users in an OU to receive a dedicated password.
    By tosca925 in forum How do you do....it?
    Replies: 4
    Last Post: 4th June 2007, 09:58 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •