# Changing/Setting Passwords in Active Directory

**URL:** <https://rubytalk.org/t/changing-setting-passwords-in-active-directory/40215>\
**Category:** ruby-talk\
**Created:** [27 August 2007 14:24 UTC](https://rubytalk.org/t/changing-setting-passwords-in-active-directory/40215 "2007-08-27T14:24:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_Holcomb](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Glen\_Holcomb](https://rubytalk.org/u/Glen_Holcomb)\
**Post date:** [27 August 2007 14:24 UTC](https://rubytalk.org/t/changing-setting-passwords-in-active-directory/40215/1 "2007-08-27T14:24:44Z")

</div>

I've been doing some searching but am not faring so well.

Does anyone know a clean and reliable way to change and or set passwords for  
Windows accounts residing in Active Directory?

I'd rather not have to generate a VB script to be run for every user account  
created.

Thanks,  
Glen

> **···**
>
> --  
> "Hey brother Christian with your high and mighty errand, Your actions speak  
> so loud, I can't hear a word you're saying."
> 
> -Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_Holcomb](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Glen\_Holcomb](https://rubytalk.org/u/Glen_Holcomb)\
**Post date:** [27 August 2007 15:18 UTC](https://rubytalk.org/t/changing-setting-passwords-in-active-directory/40215/2 "2007-08-27T15:18:49Z")

</div>

I think I'm close but something is not working somewhere. This seems to be  
the most promising approach but doesn't work:

require 'win32ole'  
require 'Win32API'

adsi = WIN32OLE.connect("LDAP://cn=#{username},PATH\_TO\_CONTAINER")

adsi.put("SetPassword", "#{password}")  
&nbsp;&nbsp;&nbsp;&nbsp;this returns nil

adsi.invoke("SetPassword", "#{password}")  
&nbsp;&nbsp;&nbsp;&nbsp;this returns the string given as the password but nothing is changed

The following VB script works just fine:

Set objUser = GetObject \_  
("LDAP://my values here")  
objUser.SetPassword "some password"

> **···**
>
> On 8/27/07, Glen Holcomb \<damnbigman@gmail.com\> wrote:
> 
> > I've been doing some searching but am not faring so well.
> > 
> > Does anyone know a clean and reliable way to change and or set passwords  
> > for  
> > Windows accounts residing in Active Directory?
> > 
> > I'd rather not have to generate a VB script to be run for every user  
> > account  
> > created.
> > 
> > Thanks,  
> > Glen
> > 
> > --  
> > "Hey brother Christian with your high and mighty errand, Your actions  
> > speak  
> > so loud, I can't hear a word you're saying."
> > 
> > -Greg Graffin (Bad Religion)
> 
> --  
> "Hey brother Christian with your high and mighty errand, Your actions speak  
> so loud, I can't hear a word you're saying."
> 
> -Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_Holcomb](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Glen\_Holcomb](https://rubytalk.org/u/Glen_Holcomb)\
**Post date:** [27 August 2007 15:43 UTC](https://rubytalk.org/t/changing-setting-passwords-in-active-directory/40215/3 "2007-08-27T15:43:33Z")

</div>

Never mind, figured it out.

I needed to do:

adsi.SetPassword("password")

> **···**
>
> On 8/27/07, Glen Holcomb \<damnbigman@gmail.com\> wrote:
> 
> > On 8/27/07, Glen Holcomb \<damnbigman@gmail.com\> wrote:  
> > \>  
> > \> I've been doing some searching but am not faring so well.  
> > \>  
> > \> Does anyone know a clean and reliable way to change and or set passwords  
> > \> for  
> > \> Windows accounts residing in Active Directory?  
> > \>  
> > \> I'd rather not have to generate a VB script to be run for every user  
> > \> account  
> > \> created.  
> > \>  
> > \> Thanks,  
> > \> Glen  
> > \>  
> > \> --  
> > \> "Hey brother Christian with your high and mighty errand, Your actions  
> > \> speak  
> > \> so loud, I can't hear a word you're saying."  
> > \>  
> > \> -Greg Graffin (Bad Religion)  
> > \>
> > 
> > I think I'm close but something is not working somewhere. This seems to  
> > be  
> > the most promising approach but doesn't work:
> > 
> > require 'win32ole'  
> > require 'Win32API'
> > 
> > adsi = WIN32OLE.connect("LDAP://cn=#{username},PATH\_TO\_CONTAINER")
> > 
> > adsi.put("SetPassword", "#{password}")  
> > &nbsp;&nbsp;&nbsp;&nbsp;this returns nil
> > 
> > adsi.invoke("SetPassword", "#{password}")  
> > &nbsp;&nbsp;&nbsp;&nbsp;this returns the string given as the password but nothing is changed
> > 
> > The following VB script works just fine:
> > 
> > Set objUser = GetObject \_  
> > ("LDAP://my values here")  
> > objUser.SetPassword "some password"
> > 
> > --  
> > "Hey brother Christian with your high and mighty errand, Your actions  
> > speak  
> > so loud, I can't hear a word you're saying."
> > 
> > -Greg Graffin (Bad Religion)
> 
> --  
> "Hey brother Christian with your high and mighty errand, Your actions speak  
> so loud, I can't hear a word you're saying."
> 
> -Greg Graffin (Bad Religion)
