Win32_LogonSession

Win32 Logon Session
root/cimv2dynamickey : LogonId

Describes the logon session or sessions associated with a user logged on to a computer system running Windows.

On this page

Main example

List instances

# All instances of Win32_LogonSession, with the main properties
Get-CimInstance -ClassName Win32_LogonSession |
    Select-Object -Property LogonId, Name, Caption, Description, Status, InstallDate

Examples

Filter with WQL

# WQL filter evaluated by the provider: LogonType = 2 (Interactive)
Get-CimInstance -ClassName Win32_LogonSession -Filter 'LogonType = 2' |
    Select-Object -Property LogonId, Name, Caption, Description, Status, InstallDate

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Decode numeric values

# Lookup table for LogonType (values documented by Microsoft)
$logonTypeName = @{
    2 = 'Interactive'
    3 = 'Network'
    4 = 'Batch'
    5 = 'Service'
    6 = 'Proxy'
    7 = 'Unlock'
    8 = 'NetworkCleartext'
    9 = 'NewCredentials'
    10 = 'RemoteInteractive'
    11 = 'CachedInteractive'
    12 = 'CachedRemoteInteractive'
    13 = 'CachedUnlock'
}

Get-CimInstance -ClassName Win32_LogonSession |
    Select-Object -Property @(
        'LogonId'
        'Name'
        'Caption'
        'Description'
        'Status'
        'InstallDate'
        @{ Name = 'LogonType'; Expression = { $logonTypeName[[int]$_.LogonType] } }
    )

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_LogonSession |
        Select-Object -Property LogonId, Name, Caption, Description, Status, InstallDate
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_LogonSession
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

9 of 9 properties
NameTypeAccessDescription
AuthenticationPackagestringread

Name of the subsystem used to authenticate the logon session.

Code
# Value of AuthenticationPackage for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, AuthenticationPackage |
    Select-Object -Property LogonId, AuthenticationPackage
Captionstringread

A short textual description of the object.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, Caption |
    Select-Object -Property LogonId, Caption
Descriptionstringread

A textual description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, Description |
    Select-Object -Property LogonId, Description
InstallDatedatetimeread

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, InstallDate |
    Select-Object -Property LogonId, InstallDate
LogonId keystringread

ID assigned to the logon session.

Code
# Value of LogonId for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId |
    Select-Object -Property LogonId
LogonTypeuint32read

Numeric value that indicates the type of logon session.

0

Used only by the System account.

Values (12)
ValueLabelDescription
2InteractiveIntended for users who are interactively using the machine, such as a user being logged on by a terminal server, remote shell, or similar process.
3NetworkIntended for high-performance servers to authenticate clear text passwords. LogonUser does not cache credentials for this logon type.
4BatchIntended for batch servers, where processes can be executed on behalf of a user without their direct intervention; or for higher performance servers that process many clear-text authentication attempts at a time, such as mail or web servers. LogonUser does not cache credentials for this logon type.
5ServiceIndicates a service-type logon. The account provided must have the service privilege enabled.
6ProxyIndicates a proxy-type logon.
7UnlockThis logon type is intended for GINA DLLs logging on users who are interactively using the machine. This logon type allows a unique audit record to be generated that shows when the workstation was unlocked.
8NetworkCleartextPreserves the name and password in the authentication packages, allowing the server to make connections to other network servers while impersonating the client. This allows a server to accept clear text credentials from a client, call LogonUser, verify that the user can access the system across the network, and still communicate with other servers.
9NewCredentialsAllows the caller to clone its current token and specify new credentials for outbound connections. The new logon session has the same local identify, but uses different credentials for other network connections.
10RemoteInteractiveTerminal Services session that is both remote and interactive.
11CachedInteractiveAttempt cached credentials without accessing the network.
12CachedRemoteInteractiveSame as RemoteInteractive. This is used for internal auditing.
13CachedUnlockWorkstation logon.
Code
# Value of LogonType for each instance
# Lookup table for LogonType (values documented by Microsoft)
$logonTypeName = @{
    2 = 'Interactive'
    3 = 'Network'
    4 = 'Batch'
    5 = 'Service'
    6 = 'Proxy'
    7 = 'Unlock'
    8 = 'NetworkCleartext'
    9 = 'NewCredentials'
    10 = 'RemoteInteractive'
    11 = 'CachedInteractive'
    12 = 'CachedRemoteInteractive'
    13 = 'CachedUnlock'
}
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, LogonType |
    Select-Object -Property @(
        'LogonId'
        @{ Name = 'LogonType'; Expression = { $logonTypeName[[int]$_.LogonType] } }
    )
Namestringread

Label by which the object is known. When subclassed, this property can be overridden to be a key property.

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, Name |
    Select-Object -Property LogonId, Name
StartTimedatetimeread

Time at which the session started.

Code
# Value of StartTime for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, StartTime |
    Select-Object -Property LogonId, StartTime
Statusstringread

String that indicates the current status of the object. Operational and non-operational status can be defined. Operational status can include "OK", "Degraded", and "Pred Fail". "Pred Fail" indicates that an element is functioning properly, but is predicting a failure (for example, a SMART-enabled hard disk drive).

Non-operational status can include "Error", "Starting", "Stopping", and "Service". "Service" can apply during disk mirror-resilvering, reloading a user permissions list, or other administrative work. Not all such work is online, but the managed element is neither "OK" nor in one of the other states.

Values include the following:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_LogonSession -Property LogonId, Status |
    Select-Object -Property LogonId, Status

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. Win32_Session
  4. Win32_LogonSession

Known subclasses

No known subclass.

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") UUID("{9083C21E-7D58-4e0e-BC30-0BC8922AFB8B}") AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.