这个密码脚本有什么作用?

-1 script passwords

在工作中的一个单位上找到了这个文件...

Set WshShell = CreateObject("WScript.Shell")
PINGFlag = Not CBool(WshShell.run("ping contoso.com -n 1 " & vSystemIdentifier,0,True))
      If PINGFlag = True Then
         'Successful ping
    'WScript.Echo "Connectivity to domain confirm."
    Call Password
      Else
         'Unsuccessful ping
    'WScript.Echo "No Connectivity to domain password check cancelled."
      End If



Function Password()

'========================================
    ' First, get the domain policy.
    '========================================
    Dim oDomain
    Dim oUser
    Dim maxPwdAge
    Dim numDays
    Dim warningDays

    warningDays = 15

    Set LoginInfo = CreateObject("ADSystemInfo")  
    Set objUser = GetObject("LDAP://" & LoginInfo.UserName & "")  
    strDomainDN = UCase(LoginInfo.DomainDNSName) 
    strUserDN = LoginInfo.UserName


    Set oDomain = GetObject("LDAP://" & strDomainDN)
    Set maxPwdAge = oDomain.Get("maxPwdAge")

    '========================================
    ' Calculate the number of days that are
    ' held in this value.
    '========================================
    numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
                    maxPwdAge.LowPart) / CCur(-864000000000)
    'WScript.Echo "Maximum Password Age: " & numDays

    '========================================
    ' Determine the last time that the user
    ' changed his or her password.
    '========================================
    Set oUser = GetObject("LDAP://" & strUserDN)

    '========================================
    ' Add the number of days to the last time
    ' the password was set.
    '========================================
    whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
    fromDate = Date
    daysLeft = DateDiff("d",fromDate,whenPasswordExpires)

    'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged

    if (daysLeft < warningDays) and (daysLeft > -1) then
        Msgbox "Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Press CTRL-ALT-DEL and" & chr(13) & "select the 'Change a password' option" & chr(13) & "Please allow enough time for password change to take effect," & chr(13) & "minimum of 15 minutes before disconnecting", 0, "PASSWORD EXPIRATION WARNING!"
    End if

    '========================================
    ' Clean up.
    '========================================
    Set oUser = Nothing
    Set maxPwdAge = Nothing
    Set oDomain = Nothing
End Function
Run Code Online (Sandbox Code Playgroud)

3D1*_*T0R 5

此脚本创建一个弹出窗口,以在用户密码即将到期时警告用户。

它最初由MarkK / Mark-K发布,作为对 Server Fault 和 Microsoft 的 TechNet 论坛上帖子的回应,自您发布的版本以来,这两个论坛都收到了更新。您在问题中包含的版本还包括 Mark K 发布的版本中不存在的一些修改。

作为参考,这里是相关服务器故障答案的链接,以及TechNet 论坛上的原始更新帖子。

另外,我发现了JitenSh在 Spiceworks 论坛上发布的此脚本生成的弹出窗口的屏幕截图:
密码过期警告: ( i ) 您的密码将在 4/10/2014 下午 2:03:42 的 4 天后过期 按 CTRL + ALT + DEL 并选择“更改密码”选项。 [好的]