Category filter
Script to get the login information of the last logged-in user on Windows
This article will tell you how to deploy scripts to find the login information of the last logged-in user on your Windows device.
Many organizations have devices that are being used by multiple users. As an organization, have you ever wanted to monitor who’s logging into your Windows device and when? Monitoring and managing these shared devices manually can be daunting for IT admins. Hexnode lets admins automate this process with its custom scripts feature for Windows devices.
PowerShell Script to get last logged on user
The PowerShell script to fetch the last logged on user on the Windows machine is given below:
1 2 3 4 5 6 7 8 9 10 11 |
if ($PSHOME -like "*syswow64*") { Write-Output 'Relaunching as x64' & (Join-Path ($PSHOME -replace 'syswow64', 'sysnative') powershell.exe) ` -File $Script:MyInvocation.MyCommand.Path ` } get-localuser | where {$_.name} | select-object lastlogon,name | sort-object lastlogon –Descending | select-object lastlogon,name -first 1|Write-Output |