• VBS处理AD帐号密码到期提醒的脚本[zt]


    原文:https://gallery.technet.microsoft.com/scriptcenter/f7f5f7ed-14ee-4d0e-81c2-7d95ce7e08f5

    '==========================================================================
    'Milan on 1/12/2011
    ’ This script can be used to notify users of when their windows passords
    ’ are going to expire. Especially useful in those cases where user does not logon
    ’ to windows with individual login and uses OWA for email
    ’ Script is currently running fine in a Exchange 2010 env with AD 2008
    '==========================================================================
    On Error Resume Next
    Const ADS_SCOPE_SUBTREE = 2
    Const SEC_IN_DAY = 86400
    Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 ’ tocheck for accounts that have “no expire” set on the password

    Dim maxPwdAge
    maxpwdage = 90 'set this according to policy in your organization
    Dim numDays
    Dim warningDays
    warningDays = 14 ’ set this according to policy in your organization

    'ADO to access Active Directory
    Set objConnection = CreateObject(“ADODB.Connection”)
    Set objCommand = CreateObject(“ADODB.Command”)
    objConnection.Provider = “ADsDSOObject”
    objConnection.Open “Active Directory Provider”
    Set objCommand.ActiveConnection = objConnection
    Set objRootDSE = GetObject(“LDAP://rootDSE”)

    DomainString = objRootDSE.Get(“dnsHostName”)

    objCommand.Properties(“Page Size”) = 1000
    objCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE

    objCommand.CommandText = “SELECT DisplayName,mail,DistinguishedName,sAMAccountName FROM ‘LDAP://OU=xxxx,DC=abcdefg,DC=com,DC=cn’” & _
    " where objectClass=‘user’"
    '" WHERE objectCategory=‘user’" 'This was creating problems where it was picking up two objects that were contacts, not users
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst 'get to the first record in the recordset
    Do Until objRecordSet.EOF
    strUser = objRecordSet.Fields(“sAMAccountName”).Value
    strDN = objRecordSet.Fields(“DistinguishedName”).Value 'This is important otherwise we cannot pull the "last Password Change date
    strMail = objRecordSet.Fields(“mail”).Value
    strFullName = objRecordSet.Fields(“DisplayName”).Value

        For Each objItem in strUser  'one record at a time  
            Set objUserLDAP = GetObject ("LDAP://" & strDN & "")  
            intCurrentValue = objUserLDAP.Get("userAccountControl") ' For checking if the account is disabled  
              
            '*******************************************************************************************  
            'BEGIN OF PASSWORD EXPIRATION WARNING  
            '*******************************************************************************************  
    
                numDays = maxpwdage  
                dtVal = objUserLDAP.PasswordLastChanged 'The latest date the user changed her/his password  
                whenPasswordExpires = DateAdd("d", numDays, dtval)  
                fromDate = Date
                daysLeft = DateDiff("d",fromDate,whenPasswordExpires)  
                If (daysLeft < warningDays) and (daysLeft > 0) then  'If 14 days or less remain until Password expires  
                    wscript.echo strFullname & "(" & strUser & "), 您的办公网域帐号将于 " & daysLeft & "天后到期。请尽快修改以免影响网络使用。" & vbcrlf
                End if  
        Next
    objRecordSet.MoveNext ' Keep going down the table  
    

    Loop

    Set objConnection = Nothing
    Set objCommand = Nothing
    Set objCommand.ActiveConnection = Nothing
    Set objRootDSE = Nothing
    Set objRecordSet = Nothing
    Set objUserLDAP = Nothing
    Set objEmail = Nothing
    WScript.Quit

  • 相关阅读:
    SQLAlchemy(2) -- SQLAlchemy的安装
    SQLAlchemy(1) -- Python的SQLAlchemy和ORM
    http-proxy-middleware及express实现反向代理
    Vue项目中的http请求统一管理
    vue.js中如何使用scss
    Vue 相关开源项目库汇总
    Vue UI组件库
    route按需加载的3种方式:vue异步组件、es提案的import()、webpack的require.ensure()
    Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流
    vuejs 和 element 搭建的一个后台管理界面
  • 原文地址:https://www.cnblogs.com/d9394/p/10611698.html
Copyright © 2020-2023  润新知