[请益] AD帐号密码到期通知-VBscript

楼主: waterboy1012 (比特币挖矿机)   2017-03-28 10:54:02
最近遇到一点AD密码到期的问题
WIN7使用者密码到期是气泡球的方式 很多人都当看不见
跟XP的强迫视窗不一样
想请问各位有经验的版大
我在网络上找到一支VBscript
想修改后拿来使用
程式如下
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set OutputFile=objFSO.OpenTextFile("d:\PasswordExpires.txt",2,true)
OutputFile.WriteLine "帐号" & vbtab & "部门" & vbtab & "密码到期日" & vbtab
& "剩余天数"
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name,distinguishedName,displayName,mail,givenName from
'LDAP://OU=zz,DC=test,DC=com' " & "Where objectClass='USER' AND
USERAccountControl='512'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Dim oDomain
Dim oUser
Dim maxPwdAge
Dim numDays
strDomainDN = "test.com"
strUserDN = strDomainDN & "/" &
objRecordSet.Fields("distinguishedName").Value
Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + maxPwdAge.LowPart) /
CCur(-864000000000)
Set oUser = GetObject("LDAP://" & strUserDN)
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)
PasswordExpiresDays=DateDiff("d", Now, whenPasswordExpires)
If abs(PasswordExpiresDays) <=10 then
OutputFile.WriteLine objRecordSet.Fields("name").Value & vbtab & _
objRecordSet.Fields("displayname").Value & vbtab & _
whenPasswordExpires & vbtab & _
"还剩 " & PasswordExpiresDays & "天变更密码"
end if
objRecordSet.MoveNext
Loop
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing
OutputFile.Close
不过遇到了点问题
whenPasswordExpires 这个如果遇到空值 他会出现 0X8000500D的错误
想请问这应该怎么改比较适合?
感谢
程式出处:
https://goo.gl/rw2YTh
http://jojochen1977.pixnet.net/blog/post/63709993-vbscript%E8%AA%9E%E6%B3%95%EF%BC%9A%E8%87%AA%E5%8B%95%E9%80%9A%E7%9F%A5ad%E4%BD%BF%E7%94%A8%E8%80%85%E5%AF%86%E7%A2%BC%E5%BF%AB%E5%88%B0%E6%9C%9F
作者: jayeose   2017-03-28 11:20:00
个人使用https://goo.gl/zeCqZ9 ,在2008R2 DC上跑很正常
楼主: waterboy1012 (比特币挖矿机)   2017-03-28 11:38:00
我的还在SERVER 2003 ~~等等来研究看看
作者: blackhippo (PH6.0 微.酸民)   2017-03-28 11:47:00
https://goo.gl/XPlO3J 这篇试试?

Links booklink

Contact Us: admin [ a t ] ucptt.com