原文: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

VBS处理AD帐号密码到期提醒的脚本[zt]的更多相关文章

  1. vbs 修改Administrator帐号密码

    Dim WshShell, oExec Set wshShell = CreateObject("WScript.Shell") Set objFSO = CreateObject ...

  2. 如何修改SharePoint2013服务器场帐号密码

    服务器远程登录帐号密码修改密码后,如何修改sharepoint服务器场管理员账户密码,今天登录了一下N久以前的搭建sharepoint2013服务器场的一台服务器器,登录进去以后直接提示帐号密码过期需 ...

  3. python3登录极路由并读取宽带帐号帐号密码.py

    python3登录极路由并读取宽带帐号帐号密码,fiddler抓包分析过程略... 步骤:1.登录路由,提取stok. 2.用stok拼成url,post请求 3.解析json数据 代码: " ...

  4. 开发Chrome Extension截取你微博的帐号密码

    Google允许开发者对Chrome浏览器做扩展,所以有了之前火爆的12306抢票软件,我 也用它抢过票,一直很好奇它怎么注入js到12306上面的.这周有空研究了下Chrome Extension, ...

  5. Ubuntu 12.04 64bit 配置完android 5.0编译环境后出现“could not write bytes: Broken pipe.”而无法进入输入帐号密码的登陆界面

    Ubuntu 12.04 64bit 配置完android 5.0编译环境后出现“could not write bytes: Broken pipe.”而无法进入输入帐号密码的登陆界面.上网问了问百 ...

  6. 用firefox 31配合KeePass密码管理器实现web帐号密码自动填写登录

    原文:http://bbs.kafan.cn/thread-1754676-1-1.html KeePass的优势:1.这是一款完全开源的密码管理器2.很多人都使用lastpass来保存密码,而这种严 ...

  7. Squid配置之使用帐号密码验证

      转自: https://blog.csdn.net/atco/article/details/43448885   1.安装squid使用root用户进行操作.先使用rpm检测是否已经安装了sql ...

  8. foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误

    foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误,收件.发件服务器配置需要用imap.ym.163.com,smtp.ym.163.com三级域名,帐 ...

  9. TortoiseGit bonobo gitserver记住帐号密码

    记住帐号密码有两种方式: 针对服务器存储用户名密码 设置方式为在windows用户存储位置创建文件_netrc,没有后缀名.用文本编辑内容,格式为   machine 115.29.141.162 只 ...

随机推荐

  1. Docker 系列01: Centos7.3 上安装docker

    Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器 ...

  2. Linux coredump 的打开和关闭

    (转载自 http://blog.sina.com.cn/s/blog_6b3765230100lazj.html) ulimit -c 输出如果为0,则说明coredump没有打开 ulimit - ...

  3. flume用场景及架构原理

    Flume是什么 1.flume可以将采集到的数据存储到HDFS上,也可以放在Hbase上. 2.flume就是一个中间插件,他的作用就是屏蔽数据源和数据存储系统的差异.可以在不同的数据源采集数据,因 ...

  4. 微服务、SOA 和 API对比与分析

    摘要: 对比微服务架构和面向服务的架构(SOA)是一个敏感的话题,常常引起激烈的争论.本文将介绍这些争论的起源,并分析如何以最佳方式解决它们.然后进一步查看这些概念如何与 API 管理概念结合使用,实 ...

  5. Ajax总结一下

    一.什么是Ajax Ajax(Asynchronous JavaScript and XML),可以理解为JavaScript执行异步网络请求.通俗的理解的话就是,如果没有Ajax技术,改变网页的一小 ...

  6. LeetCode 5. Longest Palindromic Substring & 回文字符串

    Longest Palindromic Substring 回文这种简单的问题,在C里面印象很深啊.希望能一次过. 写的时候才想到有两种情况: 454(奇数位) 4554(偶数位) 第1次提交 cla ...

  7. [Unity动画]06.子状态机

    参考链接: https://www.jianshu.com/p/6b1db3d060ac?utm_campaign=maleskine&utm_content=note&utm_med ...

  8. 47.纯 CSS 创作一个蝴蝶标本展示框

    html,body{ margin:; padding:; } body{ height: 100vh; display: flex; justify-content: center; align-i ...

  9. sparksql进阶

    scala> val df=spark.read.json("/tmp/pdf1json")df: org.apache.spark.sql.DataFrame = [age ...

  10. JavaScript 函数与对象的 简单区别

    直接上例子 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <met ...