Introduction
This tech support guide focuses on finding device usage data in Windows 11 using PowerShell. We will cover the key concepts and steps required to retrieve detailed information about device usage, including user login and screen lock times. This will help you to determine how actively a device has been used, which is important when managing a fleet of computers.
Accessing PowerShell
To begin, you need to open PowerShell with administrative privileges. You can do this by searching for "PowerShell" in the Windows 11 search bar, right-clicking on the "Windows PowerShell" result, and selecting "Run as administrator".
Finding Device Usage Data
Once PowerShell is open, you can use the following cmdlets to find device usage data:
Get Local User Session Information
The first step is to retrieve information about local user sessions. Use the following cmdlet to do this:
Get-LocalUser | Select-Object Name, AccountLockoutPolicy, LastLogonGet Device Usage Details
Next, you can retrieve detailed device usage information using the following cmdlet:
Get-WmiObject -Class Win32_OperatingSystem | Select-Object LastBootUpTime, TotalVisibleDesktopHours, LoadPercentageCalculate User Login and Screen Lock Times
With the session and device usage information, you can now calculate user login and screen lock times using the following PowerShell script:
$sessions = Get-LocalUser | Select-Object Name, AccountLockoutPolicy, LastLogon
$osInfo = Get-WmiObject -Class Win32_OperatingSystem | Select-Object LastBootUpTime, TotalVisibleDesktopHours, LoadPercentage
$startTime = $osInfo.LastBootUpTime
$endTime = Get-Date
$timeDifference = $endTime - $startTime
$totalSeconds = $timeDifference.TotalSeconds
$totalDesktopHours = [math]::Round($osInfo.TotalVisibleDesktopHours, 2)
$userSessions = @()
foreach ($session in $sessions) {
$lastLogon = $session.LastLogon
$sessionName = $session.Name
$userSession = New-Object PSObject -Property @{
SessionName = $sessionName
LastLogon = $lastLogon
LogonTime = $startTime + ($totalSeconds * ($lastLogon - $startTime).TotalSeconds / $totalDesktopHours)
}
$userSessions += $userSession
}
$userSessions | Format-Table -AutoSize
In this article, we have covered how to find device usage data in Windows 11 using PowerShell. By following the steps outlined above, you can retrieve detailed information about user sessions and device usage, and calculate user login and screen lock times. This can help you to manage your fleet of computers more effectively and make informed decisions about device usage.
References
- Get-LocalUser (Microsoft Docs)
- Get-WmiObject (Microsoft Docs)
- Win32_OperatingSystem class (Microsoft Docs)