Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows 10 / View Success and Failed Local Logon Attempts on Windows

May 2, 2023 PowerShellWindows 10Windows 11Windows Server 2019

View Success and Failed Local Logon Attempts on Windows

When investigating various incidents, an administrator needs to know who logged on to a particular Windows computer and when. You can get a history of user logons in a domain network from the domain controller logs. Nevertheless, sometimes it is easier to get information directly from the local computer’s event logs. In this article, we will show how to get and analyze the user logon events on a computer/server running Windows. These statistics will help you answer the questions “How to view who has used a Windows computer and when?” and “How to check user logon history in Windows?”.

Contents:
  • Enable User Logon Audit Policy in Windows
  • How to Find User Logon Events in Windows Event Viewer?
  • Parsing User Logon Events with PowerShell

Enable User Logon Audit Policy in Windows

First of all, enable the user logon audit policy. To configure local Group Policy settings on a standalone computer, use the gpedit.msc snap-in. If you want to enable the policy for computers in an Active Directory domain, use the domain GPO editor (gpmc.msc).

  1. Open the Group Policy Management console, create a new GPO, and assign it to Organizational Units (OUs) containing with computers and/or servers you want to enable logon event audit policy for;
  2. Open the GPO and go to Computer Configuration -> Policies -> Windows Settings -> Security Settings –> Advanced Audit Policy Configuration -> Audit Policies -> Logon/Logoff;
  3. Enable two audit policy options: Audit Logon and Audit Logoff. It will help to track both user logon and logoff events. If you want to track successful logon attempts only, check the Success option in the policy settings;
    The same section contains policy settings for auditing account lockout events, changes to Active Directory groups, etc.
    Enable Audit logon events policy in Windows
  4. Close the GPO editor and update the Group Policy settings on the clients.

How to Find User Logon Events in Windows Event Viewer?

After you have enabled logon audit policies, a logon event entry will appear in the Event Viewer log each time a user logs on to Windows. Let’s see what it looks like.

  1. Open the Event Viewer (eventvwr.msc);
  2. Expand Windows Logs and select Security;
  3. Right-click it and select Filter Current Log;
  4. Enter the event ID 4624 in the box and click OK. Filter log in Event Virwer by EventID
  5. Only user and system service logon events will be displayed with the description: An account was successfully logged on.
  6. The event description contains the name and domain of the user logged on to the computer:
    New Logon:
    Security ID: WOSHUB\a.muller
    Account Name: a.muller
    Account Domain: WOSHUB

View user logon events in Windows

Find some other useful Event IDs below:

Event IDDescription
4624A successful account logon event
4625An account failed to log on
4648A logon was attempted using explicit credentials
4634An account was logged off
4647User-initiated logoff

The filtered event log will contain more than just local user login events. There are also events for network access to this computer (when you open shared files or use shared printers), events for running different services and scheduled tasks, etc. In other words, there are a lot of events that are not related to a local user logon.

The Logon Type code can be used to filter only the events of interactive user logins to a computer console (local). The table below shows Logon Type codes.

Logon Type CodeDescription
0System
2Interactive
3Network
4Batch
5Service
6Proxy
7Unlock
8NetworkCleartext
9NewCredentials
10RemoteInteractive
11CachedInteractive
12CachedRemoteInteractive
13CachedUnlock
Entries with Logon Type 10 or 3 appear in the event log when you connect remotely to the computer’s desktop using RDP. Find out more about how to parse RDP connection logs in Windows.

According to this table, a local user logon event must contain Logon Type: 2.

This event ID will also appear if you are using the automatic Windows logon.

To filter logon events by the Logon Type, it is better to use PowerShell.

Parsing User Logon Events with PowerShell

Suppose your task is to find out which users have recently logged on to this computer. We are only interested in the interactive logon events (using the computer console) with the LogonType =2. We’ll use the Get-WinEvent cmdlet to select the events from the Event Viewer logs.

The following PowerShell script displays the logon history of users on the current computer and presents it as a graphical Out-GridView table.

$query = @'
<QueryList>
<Query Id='0' Path='Security'>
<Select Path='Security'>
*[System[EventID='4624']
and(
EventData[Data[@Name='VirtualAccount']='%%1843']
and
EventData[Data[@Name='LogonType']='2']
)
]
</Select>
</Query>
</QueryList>
'@
$properties = @(
@{n='User';e={$_.Properties[5].Value}},
@{n='Domain';e={$_.Properties[6].Value}},
@{n='TimeStamp';e={$_.TimeCreated}}
@{n='LogonType';e={$_.Properties[8].Value}}
)
Get-WinEvent -FilterXml $query | Select-Object $properties|Out-GridView

Get user logon history locally in Windows with PowerShell

If you want to select logon events for the last few days, you can add a pipe with the following condition:

|Where-Object {$_.TimeStamp -gt '27/04/23'}

You can use the Get-WinEvent cmdlet to get information from remote computers. For example, to get the user logon history from two remote computers, run this script:

'mun-rds1', 'mun-rds2' |
ForEach-Object {
Get-WinEvent -ComputerName $_ -FilterXml $query | Select-Object $properties
}

If the RPC protocol is not allowed, you can use the Invoke-Command PowerShell cmdlet to get data from remote computers:

Invoke-Command -ComputerName 'mun-rds1', 'mun-rds2' {Get-WinEvent -FilterXml $query | Select-Object $properties}

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Fix: “Something Went Wrong” Error When Installing Teams
next post
Fix: BSOD Error 0x0000007B (INACCESSABLE_BOOT_DEVICE) on Windows

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fix: Remote Desktop Licensing Mode is not Configured
  • Configuring Port Forwarding in Windows
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • How to Install Remote Server Administration Tools (RSAT) on Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • How to Delete Old User Profiles in Windows
  • Adding Drivers into VMWare ESXi Installation Image
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top