ユーザのパスワード変更時間を知る


AD運用でユーザのパスワード変更時間を知りたいことがある。
ADSI EditとかでPasswordLastChanged属性見ればいいけどめんどう。
なので簡単にわかるようプログラムしてみた。


以下、ソース。

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

strCN = InputBox("ID を半角で入力してください。","Input")

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT distinguishedName FROM 'LDAP://sample.local' WHERE objectCategory='user' " & _
        "AND cn = '" & strCN & "'" 
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    strDN = objRecordSet.Fields("distinguishedName").Value
    objRecordSet.MoveNext
Loop

Set objUser = GetObject("LDAP://" & strDN)

If null <> objUser Then
    MsgBox("PasswordLastChanged : " & objUser.PasswordLastChanged)
Else
    MsgBox("入力されたユーザが存在しません")
End If