Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD Account Unlock

Status
Not open for further replies.

sotghalz

Technical User
Apr 11, 2007
57
US
Good Morning,

I have been toying around with this script I put together and I can't figure out one piece.

The questions is how do I get "userul" to become part of Set objDomain = GetObject(??????????????)?

Thank you for your help!

''''''''''
Dim userul
Dim strCN, strOU, strDC, strProvider
Dim objDomain

Do
TryAgain = "No"

userul = InputBox("Enter Users username")

If userul = "" Then
MsgBox "You must enter the users username!"
TryAgain = "Yes"
Else
MsgBox ("You entered: " & userul)
End If

Loop While TryAgain = "Yes"

strCN = userul
strOU = "ou = Standard, ou = User Accounts, ou = PHL,"
strDC = "dc = *****, dc = *****, dc = *****"
strProvider = "LDAP://"

Set objDomain = GetObject(strProvider & strCN & strOU & strDC)

objDomain.IsAccountLocked = False
objDomain.SetInfo

''''''''''
 
Right now your ADS Path comes out as:

"LDAP://usernameou=Standard, ou=User Accounts, ou=PHL, dc=*****, dc=*****"

So for starters, you need to get CN= in front of the username and a comma behind it.

try this

Code:
strCN = "CN= " & userul & ", "
 
I get an error:
Line = 27
error = (null)
code = 80072030
source = (null)

System: There is no such object on the server

I have modified the whole script but put your suggestion in. Here is the whole script:

Code:
' This VBScript code unlocks a locked user.

Dim userul
Dim strCN, strOU, strDC, strProvider

MsgBox ("****Copy text in Username field****")

Do
  TryAgain = "No"
  
  userul = InputBox("Enter Users username") 

  If userul = "" Then
    MsgBox "You must enter the users username!"
      TryAgain = "Yes"
  Else
    MsgBox ("You entered: " & userul)
  End If

Loop While TryAgain = "Yes"

strCN = "CN=" & userul &", "
strOU = "ou=Standard,ou=User Accounts,ou=PHL,"
strDC = "dc=*****,dc=*****,dc=*****"
strProvider = "LDAP://"

[COLOR=red]set objUser = GetObject(strProvider & strCN  & strCN  & strOU  & strDC)[/color]

  if objUser.IsAccountLocked = TRUE then
     objUser.IsAccountLocked = FALSE
     objUser.SetInfo
     WScript.Echo "Account unlocked"
  Else
     WScript.Echo "Account not locked"
  End if
 
Got it to work. This code has an extra & strCN:

Code:
set objUser = GetObject(strProvider & strCN  & strCN  & strOU  & strDC)


Thanks for all your help.

Chase
 
For future reference msgBox is a handy tool during coding to make sure you are putting your strings together right.

Like before you call GetObject throw in a temporary:

msgBox(strProvider & strCN & strCN & strOU & strDC)

that will throw up a message box with the string and an ok button so you can see what you are actually passing to GetObject. You would have caught your error right away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top