Jump to content
Sign in to follow this  

Active Directory: SetPassword() Help!

Recommended Posts


Hey guys. I'm trying to work on a GUI that acts as a user control panel for Active Directory Management.

One of the first things that I'm trying to accomplish is adding a user. Here is my CreateUser() function:

Func CreateUser($userid, $firstname, $lastname)
    $domain = $array_UserControl[1][1]
    $suffix = $array_UserControl[2][1]
    $cn = $array_UserControl[3][1]
    $servername = $array_UserControl[4][1]
    $defaultpassword = "apassword4u"
    $objOU = ObjGet("LDAP://cn=" & $cn & ",dc=" & $domain & ",dc=" & $suffix)
    $objUser = $objOU.Create("User", "cn="& $firstname & " " & $lastname)
    $objUser.Put ("userPrincipalName", "" &  $userid & "@" & $domain & "." & $suffix)
    $objUser.Put ("sAMAccountName", $userid)
    $objUser.Put ("profilePath", "\\" & $servername & "\profiles\" & $userid)
    $objUser.SetPassword ($defaultpassword)
    $objApp = ObjCreate("Wscript.Shell")
    $objUser.AccountDisabled = 0    
    $objUser.Put ("pwdLastSet", 0)


However, when I run it, it tells me that when it gets to the SetPassword() part, it fails! No other description aside from that it failed.

What am I doing wrong? Every other source and post that I have checked show that I am using the correct syntax. Please help!



I thought I posted this in the General Help and Support. I am reposting it there, feel free to delete this thread. My apologies.*

Edited by Seen

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.