I am trying to use the SetPassword method on a DirectoryEntry.
$Root = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc.ourdomain.com/OU=Users,DC=dc,DC=ourdomain,DC=com", $ldapusername, $ldappassword, "Secure")
$objUser = $Root.Create("user","CN=$DisplayName")
$objUser.Put("sAMAccountName", "$username")
$objUSer.Put("userPrincipalName","$userPrincipalName")
$objUser.Put("givenName", "$firstname")
$objUser.Put("sn", "$lastname")
$objUser.Put("description", "$description")
$objUser.Put("displayName", "$DisplayName")
$objUser.Put("mail", "$email")
$objUser.Put("company", "$Company")
$objUser.SetInfo()
$ObjUser.psbase.Invoke("SetPassword","qW12eR34")
$objUser.psbase.InvokeSet(“AccountDisabled”,$false)
$objUser.SetInfo()
Whenever I run this, I keep getting the following error:
Exception calling "Invoke" with "2" argument(s): "The RPC server is unavailable. (
Exception from HRESULT: 0x800706BA)"
At E:\Untitled1.ps1:27 char:23 + $ObjUser.psbase.Invoke <<<< ("SetPassword","qW12eR34")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
I am able to reset the password through Set-ADAccountPassword just fine, but I need to be able to do it through this way.. This function creates the user just fine, and it also sets the AccountDisable to false as it should do. But it keeps failing on SetPassword..
I read around here that some people mentioned it could be due to blocked ports etc (Everything is open between the two servers) and some mentioned the AuthenticationType has to be set to Secure.. But I am setting it to Secure, and I am still having the same problem.
Thanks in advance..
Ok so i am pretty sure i found out why this is, i was trying to do something the same, and confirmed all ports (this works on port 135), are open, but port 135 never was able to recieve traffic from the world, called my ISP and yes, most ISP's these days, and with more to follow WILL block all traffic incoming on this port, so that's what your error is telling you. It is trying to perform the actions but the requests are never reaching the server. Call your provider and confirm, else check port 135 in your firewall rules on your incoming server (temporarily disabling firewall for testing will tell you)
User contributions licensed under CC BY-SA 3.0