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
VBS处理AD帐号密码到期提醒的脚本[zt]的更多相关文章
- vbs 修改Administrator帐号密码
Dim WshShell, oExec Set wshShell = CreateObject("WScript.Shell") Set objFSO = CreateObject ...
- 如何修改SharePoint2013服务器场帐号密码
服务器远程登录帐号密码修改密码后,如何修改sharepoint服务器场管理员账户密码,今天登录了一下N久以前的搭建sharepoint2013服务器场的一台服务器器,登录进去以后直接提示帐号密码过期需 ...
- python3登录极路由并读取宽带帐号帐号密码.py
python3登录极路由并读取宽带帐号帐号密码,fiddler抓包分析过程略... 步骤:1.登录路由,提取stok. 2.用stok拼成url,post请求 3.解析json数据 代码: " ...
- 开发Chrome Extension截取你微博的帐号密码
Google允许开发者对Chrome浏览器做扩展,所以有了之前火爆的12306抢票软件,我 也用它抢过票,一直很好奇它怎么注入js到12306上面的.这周有空研究了下Chrome Extension, ...
- 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.”而无法进入输入帐号密码的登陆界面.上网问了问百 ...
- 用firefox 31配合KeePass密码管理器实现web帐号密码自动填写登录
原文:http://bbs.kafan.cn/thread-1754676-1-1.html KeePass的优势:1.这是一款完全开源的密码管理器2.很多人都使用lastpass来保存密码,而这种严 ...
- Squid配置之使用帐号密码验证
转自: https://blog.csdn.net/atco/article/details/43448885 1.安装squid使用root用户进行操作.先使用rpm检测是否已经安装了sql ...
- foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误
foxmail收取163企业邮箱设置,不能直接用foxmail默认的配置,否则一直提示帐号密码错误,收件.发件服务器配置需要用imap.ym.163.com,smtp.ym.163.com三级域名,帐 ...
- TortoiseGit bonobo gitserver记住帐号密码
记住帐号密码有两种方式: 针对服务器存储用户名密码 设置方式为在windows用户存储位置创建文件_netrc,没有后缀名.用文本编辑内容,格式为 machine 115.29.141.162 只 ...
随机推荐
- 17 RAID与mdadm管理命令
在"14 磁盘及文件系统管理详解"中,我们详细介绍了磁盘的工作原理,但是,有一点我们一定要明白,作为现在存储数据的主要设备,机械磁盘早就是上个世纪的产品,而它的读写速度与内存.CP ...
- Django中的跨表查询,多表查询。
一:Django中的ORM进行操作. 必须掌握的十三条: <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 & ...
- Spring中@Component的作用
今天在写程序的时候看见一个以前没有见过的注解(@Component),在网上查找过后,经过实践,决定把它记录下来. 1.@controller 控制器(注入服务) 用于标注控制层,相当于struts中 ...
- linux守护进程与&的区别
1.默认情况下,进程是在前台运行的,这时就把shell占据了(有很多日志打印输出),我们无法进行其他操作.所以对于没有交互的进程,很多时候我们希望将其在后台启动,可以在启动参数的时候加一个&实 ...
- MySQL关于sql_mode的修改(timestamp的默认值不正确)
timestamp的默认值不正确原因: MySQL5.7版本中有了一个STRICT mode(严格模式),而在此模式下默认是不允许设置日期的值为全0值的,所以想要解决这个问题,就需要修改sql_mod ...
- 自动化运维工具----ansible
ansible是新出现的运维工具是基于Python研发的糅合了众多老牌运维工具的优点实现了批量操作系统配置.批量程序的部署.批量运行命令等功能. 主要模块以及功能: 1 command 2 user ...
- android 开发 写一个RecyclerView布局的聊天室,并且添加RecyclerView的点击事件
实现思维顺序: 1.首先我们需要准备2张.9的png图片(一张图片为左边聊天泡泡,一个图片为右边的聊天泡泡),可以使用draw9patch.bat工具制作,任何图片导入到drawable中. 2.需要 ...
- 20165205 2017-2018-2 《Java程序设计》第六周学习总结
20165205 2017-2018-2 <Java程序设计>第六周学习总结 教材学习内容总结 String类 String对象(常量,对象) 字符串并置(结果仍是常量) 常用方法 len ...
- CMD命令行合并多个txt文件到一个txt文件
运行->输入CMD回车 输入: Copy G:\MyFolder\*.txt G:\NewFolder\a.txt 回车即可 意思是将G:\MyFolder\下的所有txt文本内容复制到G:\ ...
- First C++
第一天接触C++,根据老师的作业写了两行代码...保存到Github了. https://github.com/BlackDn 首先是认识到自己的一些小错误,如打代码的时候会忘记这一行最后加“:”.可 ...