Option Explicit
***
Dim objWMIService, colItems, WshNetwork, strComputer
Dim objUser, objItem, dtmLastLogin, strLogonInfo
Dim filesys, filetxt, Writetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WshNetwork = CreateObject("Wscript.Network")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("LastLogon.txt", ForAppending, True)
strComputer = WshNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_UserAccount Where Domain = '" & strComputer & "'")
Writetxt = ""
For Each objItem in colItems
dtmLastLogin = ""
On Error Resume Next
Set objUser = GetObject("WinNT://" & strComputer _
& "/" & objItem.Name & ",user")
dtmLastLogin = objUser.lastLogin
On Error Goto 0
strLogonInfo = strLogonInfo & vbCrLf & objItem.Name & ": " & dtmLastLogin
Next
Writetxt=Writetxt & strLogonInfo
filetxt.WriteLine(Writetxt)
filetxt.Close
After that I had to modify script, boss wanted to know, which users are disabled so after objItem.Name you can add any object like objItem.Dsiabled so after perturbations my string looks like this
strLogonInfo = strLogonInfo & vbCrLf & objItem.Name & " Time " & dtmLastLogin & " Disabled " & objItem.Disabled
Notice empty spaces, it is for export to excel. Possible Items can be found here I discovered other computer was mapped via CredentiialManager so they was not actually active, but it shows anyway realy inactive users.
Nav komentāru:
Ierakstīt komentāru