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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with AD / VBScript

Status
Not open for further replies.

snakeeyes1978

Programmer
Jan 11, 2005
70
AU
This script doesn't seem to work - can anyone see the problem?

On Error Resume Next

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strDNS = "LDAP://cn=Auto-IT," & strDNSDomain
'I have tested this connection and strDNS comes out as: LDAP://cn=Users,DC=mydomain,DC=com

Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Set objContainer = GetObject(strDNS)
objContainer.Filter = Array("user")
For Each objUser In objContainer
lngFlag = objUser.Get("userAccountControl")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD) = 0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag XOR ADS_UF_DONT_EXPIRE_PASSWD
objUser.SetInfo
End If
Next
wscript.echo "Done"
 
> lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
> objUser.Put "userAccountControl", lngFlag XOR ADS_UF_DONT_EXPIRE_PASSWD
You've applied twice xor which is equivalent to keep the original flag unchanged.
 
Spot on. Here's the corrected script which works in case anyone else comes across it :)

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strDNS = "LDAP://OU=Users," & strDNSDomain

Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Set objContainer = GetObject(strDNS)
objContainer.Filter = Array("user")
For Each objUser In objContainer
lngFlag = objUser.Get("userAccountControl")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD) = 0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag
objUser.SetInfo
End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top