0

I am trying to write a VBScript that meets 2 requirements:

  1. It unlocks a user's account.
  2. It can do so and reference the user using the samAccountName.

#1 works. However, the below script I have gotten working only references the user with their full AD name.

' UnlockUserAccount.vbs
Option Explicit

'Get the arguments
dim oArgs, strUser, strContainer
set oArgs = WScript.Arguments
strUser = "CN=" & trim(oArgs(0)) & "," 
strContainer = "OU=User Accounts,OU=Staff,OU=Org," 

' Bind to Active Directory and get the user object
dim objRootLDAP, objUser
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objUser = GetObject("LDAP://" & strUser & strContainer & objRootLDAP.Get("defaultNamingContext"))

'Unlock the user's account
objUser.IsAccountLocked = False
objUser.SetInfo

Wscript.Quit(1)

For example, suppose we have user 'bsmith', whose full name is Bill Smith.

I can only call this script and have it work by passing in "Bill Smithi" as the user.

How do I reference the user passing in "bsmith"? I can't figure this out.

uSlackr
  • 6,412
  • 21
  • 37
dthree
  • 367
  • 1
  • 8
  • 26
  • 2
    Given that VBS is nearly obsolete, I highly recommend you try this in powershell. It will be nearly trivial using get-aduser and set-aduser get-aduser bsmith |Unlock-ADAccount – uSlackr May 16 '14 at 13:22
  • @uSlackr Can you turn your comment into an answer? That was easier than drinking milk and worked perfectly! – dthree May 16 '14 at 16:50

1 Answers1

1

Given that VBS is nearly obsolete, I recommend you try this in PowerShell. It will be nearly trivial using get-aduser and set-aduser. Try this:

 get-aduser bsmith |Unlock-ADAccount
uSlackr
  • 6,412
  • 21
  • 37