Skip to content

Commit 551e29c

Browse files
committed
Add LastLogon.ps1
1 parent 058b1c4 commit 551e29c

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Option Explicit
2-
Dim objWMIService, colItems, WshNetwork, strComputer
3-
Dim objUser, objItem, dtmLastLogin, strLogonInfo
4-
Set WshNetwork = CreateObject("Wscript.Network")
5-
strComputer = WshNetwork.ComputerName
6-
7-
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
8-
Set colItems = objWMIService.ExecQuery _
9-
("Select * from Win32_UserAccount Where Domain = '" & strComputer & "'")
10-
11-
For Each objItem in colItems
12-
dtmLastLogin = ""
13-
On Error Resume Next
14-
Set objUser = GetObject("WinNT://" & strComputer _
15-
& "/" & objItem.Name & ",user")
16-
dtmLastLogin = objUser.lastLogin
17-
On Error Goto 0
18-
19-
strLogonInfo = strLogonInfo & vbCrLf & objItem.Name & ": " & dtmLastLogin
20-
Next
1+
Option Explicit
2+
Dim objWMIService, colItems, WshNetwork, strComputer
3+
Dim objUser, objItem, dtmLastLogin, strLogonInfo
4+
Set WshNetwork = CreateObject("Wscript.Network")
5+
strComputer = WshNetwork.ComputerName
6+
7+
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
8+
Set colItems = objWMIService.ExecQuery _
9+
("Select * from Win32_UserAccount Where Domain = '" & strComputer & "'")
10+
11+
For Each objItem in colItems
12+
dtmLastLogin = ""
13+
On Error Resume Next
14+
Set objUser = GetObject("WinNT://" & strComputer _
15+
& "/" & objItem.Name & ",user")
16+
dtmLastLogin = objUser.lastLogin
17+
On Error Goto 0
18+
19+
strLogonInfo = strLogonInfo & vbCrLf & objItem.Name & ": " & dtmLastLogin
20+
Next
2121
MsgBox strLogonInfo, vbOKOnly + vbInformation, "Last Logon Information for Local Users"

Last logon time/LastLogon.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Get-LocalUser | Format-Table -Property Name,FullName,LastLogon

README.markdown

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ There was a period of time when Windows was plagued with bugs that corrupted the
3535

3636
## Last logon time
3737

38-
`LastLogon.vbs` takes a long time to run, but returns a list of all local users and the date and time of their last logon action.
39-
40-
A matter of licensing: I did not write this script. The user who posted it was called `Corvus1` and posted it in educational spirit.
38+
1. `LastLogon.ps1` returns a list of all local user accounts, as well as the date and time of their last logon.
39+
2. `LastLogon (Deprecated).vbs` takes a long time to run, but returns a list of all local user accounts, as well as the date and time of their last logon. A matter of licensing: I did not write this script. The user who posted it was called `Corvus1` and posted it in educational spirit. It's very old and outdated anyway; it's best not to use it.
4140

4241
## Maintenance
4342

0 commit comments

Comments
 (0)