Main example
List instances
# All instances of Win32_Thread, with the main properties
Get-CimInstance -ClassName Win32_Thread |
Select-Object -Property @(
'CSName'
'OSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'InstallDate'
)Examples
Filter with WQL
# WQL filter evaluated by the provider: ExecutionState = 3 (Running)
Get-CimInstance -ClassName Win32_Thread -Filter 'ExecutionState = 3' |
Select-Object -Property @(
'CSName'
'OSCreationClassName'
'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 ExecutionState (values documented by Microsoft)
$executionStateName = @{
0 = 'Unknown'
1 = 'Other'
2 = 'Ready'
3 = 'Running'
4 = 'Blocked'
5 = 'Suspended Blocked'
6 = 'Suspended Ready'
}
# Lookup table for ThreadState (values documented by Microsoft)
$threadStateName = @{
0 = 'Initialized'
1 = 'Ready'
2 = 'Running'
3 = 'Standby'
4 = 'Terminated'
5 = 'Waiting'
6 = 'Transition'
7 = 'Unknown'
}
Get-CimInstance -ClassName Win32_Thread |
Select-Object -Property @(
'CSName'
'OSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'InstallDate'
)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_Thread |
Select-Object -Property @(
'CSName'
'OSCreationClassName'
'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_Thread
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, FlagsProperties
| Name | Type | Access | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Caption# | string | read | Short description of the object. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CreationClassName# key | string | read | Name of the first concrete class to appear in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, this property allows all instances of this class and its subclasses to be uniquely identified. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CSCreationClassName# key | string | read | Creation class name of the scoping computer system. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CSName# key | string | read | Name of the scoping computer system. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Description of the object. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ElapsedTime# | uint64 | read | Total execution time, in milliseconds, given to this thread since its creation. For more information about using uint64 values in scripts, see Scripting in WMI. Unit: milliseconds Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ExecutionState# | uint16 | read | Current operating condition of the thread. Values (7)
Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Handle# | string | read | Handle to a thread. The handle has full access rights by default. With the correct security access, the handle can be used in any function that accepts a thread handle. Depending on the inheritance flag specified when it is created, this handle can be inherited by child processes. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Object was installed. This property does not need a value to indicate that the object is installed. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| KernelModeTime# | uint64 | read | Time in kernel mode, in 100 nanosecond units. If this information is not available, a value of 0 (zero) should be used. For more information about using uint64 values in scripts, see Scripting in WMI. Unit: 100 nanoseconds Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Label by which the object is known. When subclassed, the property can be overridden to be a key property. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OSCreationClassName# key | string | read | Creation class name of the scoping operating system. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OSName# key | string | read | Name of the scoping operating system. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Priority# | uint32 | read | Dynamic priority of the thread. Each thread has a dynamic priority that the scheduler uses to determine which thread to execute. Initially, a thread's dynamic priority is the same as its base priority. The system can raise and lower the dynamic priority, to ensure that it is responsive (guaranteeing that no threads are starved for processor time). The system does not boost the priority of threads with a base priority level between 16 and 31. Only threads with a base priority between 0 and 15 receive dynamic priority boosts. Higher numbers indicate higher priorities. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PriorityBase# | uint32 | read | Current base priority of a thread. The operating system may raise the thread's dynamic priority above the base priority if the thread is handling user input, or lower it toward the base priority if the thread becomes compute-bound. The PriorityBase property can have a value between 0 and 31. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProcessCreationClassName# key | string | read | Value of the scoping process CreationClassName property. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProcessHandle# | string | read | Process that created the thread. The contents of this property can be used by Windows application programming interface (API) elements. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StartAddress# | uint32 | read | Starting address of the thread. Because any application with appropriate access to the thread can change the thread's context, this value may only be an approximation of the thread's starting address. Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Status# | string | read | Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states. The values are: Values (12)
Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ThreadState# | uint32 | read | Current execution state for the thread. Values (8)
Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ThreadWaitReason# | uint32 | read | Reason why the thread is waiting. This value is only valid if the ThreadState member is set to Transition (6). Event pairs allow communication with protected subsystems. Values (21)
Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UserModeTime# | uint64 | read | Time in user mode, in 100 nanoseconds units. If this information is not available, a value of 0 (zero) should be used. For more information about using uint64 values in scripts, see Scripting in WMI. Unit: 100 nanoseconds Code |
Remarks
The Win32_Thread class is derived from CIM_Thread.
Overview
For routine day-to-day monitoring, there is usually little reason to have a detailed list of threads and their associated properties. Computers create and delete thousands of threads during the course of a day, and few of these creations or deletions are meaningful to anyone but the developer who wrote the software.
However, when you are troubleshooting problems with an application, tracking the individual threads for a process allows you to identify when threads are created and when (or if) they are destroyed. Because threads that are created but not destroyed cause memory leaks, tracking individual threads can be useful information for support technicians. Likewise, identifying thread priorities can help pinpoint threads that, by running at an abnormally high priority, are preempting CPU cycles needed by other threads and other processes.
Using Win32_Thread
As implied in the preceding syntax block, the Win32_Thread class does not report the name of the process under which each thread runs. Instead, it reports the ID of the process under which the thread runs. To return the name of a process and a list of all its threads, your script must:
1. Connect to the Win32_Process class and return the list of processes and their process IDs.
2. Temporarily store this information in an array or Dictionary object.
3. For each process ID, return the list of threads for that process, and then display the process name and the list of threads.
Inheritance
Superclass chain
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("{8502C4DD-5FBB-11D2-AAC1-006008C78BC7}") 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.