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, InstallDateExamples
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, InstallDateThe 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, FlagsProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AuthenticationPackage# | string | read | Name of the subsystem used to authenticate the logon session. Code | |||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | A short textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||
| Description# | string | read | A textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Indicates when the object was installed. Lack of a value does not indicate that the object is not installed. Code | |||||||||||||||||||||||||||||||||||||||
| LogonId# key | string | read | ID assigned to the logon session. Code | |||||||||||||||||||||||||||||||||||||||
| LogonType# | uint32 | read | Numeric value that indicates the type of logon session. 0 Used only by the System account. Values (12)
Code | |||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Label by which the object is known. When subclassed, this property can be overridden to be a key property. Code | |||||||||||||||||||||||||||||||||||||||
| StartTime# | datetime | read | Time at which the session started. Code | |||||||||||||||||||||||||||||||||||||||
| Status# | string | read | 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)
Code |
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- Win32_Session
- 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
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.