Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


[Solved]Set AD password never expires script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,64416
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved]Set AD password never expires script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 [Solved]Set AD password never expires script - 9/21/2008 2:14:53 PM   
  netxman

 

Posts: 113
Score: 0
Joined: 8/1/2005
Status: offline
I want to set all AD users' password to never expire.

I got this on on the internet. But always got an error when running it.

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT Name,ADsPath FROM 'LDAP://ou=it,dc=ipcoreinc,dc=com' WHERE objectCategory='user' "
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst------------------------------------------------------------------------------------------This is Line 20
Do Until objRecordSet.EOF
strADpath = objRecordSet.Fields("ADsPath").Value
Set objPath = GetObject(strADPath)
intUAC = objPath.Get("userAccountControl")
If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
Wscript.echo objRecordSet.Fields("name").Value&":Already enabled"
Else
objPath.Put "userAccountControl", intUAC XOR ADS_UF_DONT_EXPIRE_PASSWD
objPath.SetInfo
WScript.Echo objRecordSet.Fields("name").Value&":Password never expires is now enabled"
End If
objRecordSet.MoveNext
Loop



Error is:

Line: 20
Char: 1
Error: A referral was returned from the server.
Code: 8007202B
Source:  Provider


Please help.

< Message edited by netxman -- 9/22/2008 12:08:47 PM >
 
 
Post #: 1
 
 RE: Set AD password never expires script - 9/21/2008 2:29:02 PM   
  dm_4ever


Posts: 2670
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You don't really need the MoveFirst and if anything I see you getting an error for not defining the following (at least from the example posted that is)

intUAC
ADS_UF_DONT_EXPIRE_PASSWD


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netxman)
 
 
Post #: 2
 
 RE: Set AD password never expires script - 9/21/2008 7:13:02 PM   
  netxman

 

Posts: 113
Score: 0
Joined: 8/1/2005
Status: offline
Thanks dm_4ever.

Is this a definition for intUAC? Within the code.

intUAC = objPath.Get("userAccountControl")

And I added another

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 
 
The whole code is:

'On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT Name,ADsPath FROM 'LDAP://ou=it,dc=ipcoreinc,dc=com'  WHERE objectCategory='user' "
Set objRecordSet = objCommand.Execute----------------------------------------------------------------------------------Here is line 18

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADpath = objRecordSet.Fields("ADsPath").Value
Set objPath = GetObject(strADPath)
intUAC = objPath.Get("userAccountControl")
If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
'Wscript.echo objRecordSet.Fields("name").Value&":Already enabled"
Else
objPath.Put "userAccountControl", intUAC XOR ADS_UF_DONT_EXPIRE_PASSWD
objPath.SetInfo
'WScript.Echo objRecordSet.Fields("name").Value&":Password never expires is now enabled"
End If
objRecordSet.MoveNext
Loop

 
 
 
Then got this error.  What's the table?
 
Line: 18
Char: 1
Error: Table does not exist.
Code: 80040E37
Source:  Provider

Thanks.

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Set AD password never expires script - 9/22/2008 1:48:23 AM   
  dm_4ever


Posts: 2670
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Works just fine for me....are you sure you are specifying the correct adspath for the OU you are trying to look under?

LDAP://ou=it,dc=ipcoreinc,dc=com

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to netxman)
 
 
Post #: 4
 
 RE: Set AD password never expires script - 9/22/2008 12:08:18 PM   
  netxman

 

Posts: 113
Score: 0
Joined: 8/1/2005
Status: offline
Hey, dm_4ever

So appreciate for your kindly help. It's totally my fault.

I got this code and replace the LDAP using the wrong domain's. (I have two domains.)

Change it back and everything goes well.

Thanks.

(in reply to dm_4ever)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved]Set AD password never expires script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts