[請益] AD帳號密碼到期通知-VBscript
最近遇到一點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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.249.56.98
※ 文章網址: https://www.ptt.cc/bbs/MIS/M.1490669646.A.194.html
推
03/28 11:20, , 1F
03/28 11:20, 1F
→
03/28 11:38, , 2F
03/28 11:38, 2F
→
03/28 11:47, , 3F
03/28 11:47, 3F
再出錯的地方
加入一行 On Error Resume Next
目前有跑出結果
有負數的產生
感謝協助
※ 編輯: waterboy1012 (60.249.56.98), 03/28/2017 13:30:13
MIS 近期熱門文章
PTT職涯區 即時熱門文章