我正在尝试使用 VBScript 更改 Active Directory 中用户的密码到期日期。我有获取有关用户密码的信息的代码,但我找不到有关如何更改密码的任何信息。任何帮助将不胜感激!
这是我的代码:
Const SEC_IN_DAY = 86400
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Set objOU = GetObject("LDAP://CN=[username],OU=Users,OU=New York,OU=NA,OU=[domain],DC=[domain],DC=firm")
intCurrentValue = objOU.Get("userAccountControl")
If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then
wscript.echo "The password does not expire."
Else
dtmValue = objOU.PasswordLastChanged
Wscript.echo "The password was last changed on " & _
DateValue(dtmValue) & " at " & TimeValue(dtmValue) & VbCrLf & _
"The difference between when the password was last set" & VbCrLf & _
"and today is " & int(now - dtmValue) & " days"
intTimeInterval = int(now - dtmValue)
Set objDomainNT = GetObject("WinNT://ropesgray")
intMaxPwdAge = objDomainNT.Get("MaxPasswordAge")
If intMaxPwdAge < 0 Then
WScript.Echo "The Maximum Password Age is set to 0 in the " & _
"domain. Therefore, the password does not expire."
Else
intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY)
Wscript.echo "The maximum password age is " & intMaxPwdAge & " days"
If intTimeInterval >= intMaxPwdAge Then
Wscript.echo "The password has expired."
Else
Wscript.echo "The password will expire on " & _
DateValue(dtmValue + intMaxPwdAge) & " (" & _
int((dtmValue + intMaxPwdAge) - now) & " days from today" & ")."
End If
End If
End If
'strUserPrincipalName = objOU.Get("userPrincipalName")
'strSAMAccountName = objOU.Get("sAMAccountName")
'strMaxPWAge = objOU.Get("manager")
'WScript.Echo strUserPrincipalName
'WScript.Echo strSAMAccountName
'WScript.Echo strMaxPWAge
您可以使用pwdLastSet
属性来更改密码过期时间,但可能不是您想要的方式。pwdLastSet
是自 1601 年 1 月 1 日中午 12:00 以来 100 纳秒间隔的数量。
根据微软文档 http://msdn.microsoft.com/en-us/library/ms677943%28v=vs.85%29.aspx,该属性仅接受两个值 0 或 -1。
尝试这个 :
- Set
pwdLastSet
为 0,这意味着从未设置过密码。
- 然后,设置
pwdLastSet
为-1,这意味着密码刚刚被设置。所以出现的值pwdLastSet
是当前日期/时间。
我以前在 W2K3 中使用过,它仍然可以在 W2H8 R2 上使用。
You can 找到一个工具 http://www.silogix.fr/conversion-dentiers-64-bits-en-dates-relative-ou-absolue.aspx(对不起,法语)允许您根据自 1601 年 1 月 1 日中午 12:00 以来的 100 纳秒间隔创建日期/时间。
当心它延长了密码的持续时间,这不利于安全。
我希望它有帮助。
JP
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)