Vbscript 使用VBS更改Active Directory中的密码过期日期

Vbscript 使用VBS更改Active Directory中的密码过期日期,vbscript,active-directory,passwords,Vbscript,Active Directory,Passwords,我正在尝试使用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],

我正在尝试使用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
Const SEC_IN_DAY=86400
Const ADS_UF_not_EXPIRE_PASSWD=&h10000
设置objOU=GetObject(“LDAP://CN=[username],OU=Users,OU=newyork,OU=NA,OU=[domain],DC=[domain],DC=firm”)
intCurrentValue=objOU.Get(“userAccountControl”)
如果intCurrentValue和ADS不过期,则
wscript.echo“密码不会过期。”
其他的
dtmValue=objOU.PasswordLastChanged
Wscript.echo“密码上次更改时间为”&_
日期值(dtmValue)&“at”&时间值(dtmValue)&VbCrLf&_
“上次设置密码时的差异”&VbCrLf&_
今天是“&int(now-dtmValue)&days”
intTimeInterval=int(现在为-dtmValue)
设置objdomannt=GetObject(“WinNT://ropesgray”)
intMaxPwdAge=objdomannt.Get(“MaxPasswordAge”)
如果intMaxPwdAge<0,则
Echo“在”&_
域。因此,密码不会过期
其他的
intMaxpDage=(intMaxpDage/秒/天)
Wscript.echo“最大密码期限为”&intMaxPwdAge&“天”
如果intTimeInterval>=intMaxPwdAge,则
Wscript.echo“密码已过期。”
其他的
Wscript.echo“密码将于到期”&_
日期值(dtmValue+intMaxPwdAge)和“(”和_
int((dtmValue+intMaxPwdAge)-now)和“从今天开始的天数”和“
如果结束
如果结束
如果结束
'strUserPrincipalName=objOU.Get(“userPrincipalName”)
'strSAMAccountName=objOU.Get(“sAMAccountName”)
'strMaxPWAge=objOU.Get(“经理”)
'WScript.Echo strusterPrincipalName
'WScript.Echo strsacmaccountname
'WScript.Echo strmaxpawage

您可以使用
pwdLastSet
属性更改密码过期时间,但可能不是您想要的方式
pwdLastSet
是自1601年1月1日上午12:00起的100纳秒间隔数。 根据,此属性只接受两个值0或-1

试试这个:

  • pwdLastSet
    设置为0,这意味着从未设置过密码
  • 然后,将
    pwdLastSet
    设置为-1,这意味着刚刚设置了密码。因此,
    pwdLastSet
    中显示的值是当前日期/时间
  • 我以前在W2K3中使用过,现在它还在W2H8R2上工作

    您可以从1601年1月1日上午12:00开始(法语中为“对不起”)以100纳秒的间隔创建日期/时间

    小心点它会延长密码持续时间,这对安全性不利

    我希望有帮助


    JP

    我找到了需要更改的属性(我想):PasswordLastChanged,但我无法设置它。我尝试设置另一个属性(邮政编码),并能够使用objUser.SetInfo进行设置,但当我尝试设置日期时,同一行抛出一个错误:objUser.Put“PasswordLastChanged”,DateValue(“31-Mar-11”)objUser.setinfoThank JP-我听说了0和-1值可以更改此值,但是我能像你说的那样把它调成另一个数字吗?(自1601年1月1日起的100纳秒间隔数)我想将密码设置为3天后过期。您知道这是否可行吗?我认为您不能在pwdLastSet中设置除(0,-1)之外的其他值。你到底想做什么?是否要要求某些用户在固定日期后3天内重新键入密码?我将尝试更改accountExpires属性,我将进行测试。我要更改用户密码的过期日期或设置密码过期的天数。因此,对于给定的用户,我想说“您的密码将在3天后过期(或在2011年4月9日到期),因此您必须在此时更改密码”。谢谢请记住,我希望更改密码过期日期,而不是帐户过期日期。accountExpires肯定不是您需要的。