Main example
List instances
# All instances of Win32_PnPEntity, with the main properties
Get-CimInstance -ClassName Win32_PnPEntity |
Select-Object -Property @(
'Name'
'Status'
'PNPClass'
'Manufacturer'
'DeviceID'
'ConfigManagerErrorCode'
)Examples
Filter with WQL
# WQL filter evaluated by the provider: devices in error
Get-CimInstance -ClassName Win32_PnPEntity -Filter 'ConfigManagerErrorCode <> 0' |
Select-Object -Property @(
'Name'
'Status'
'PNPClass'
'Manufacturer'
'DeviceID'
'ConfigManagerErrorCode'
)The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Decode numeric values
# Lookup table for ConfigManagerErrorCode (values documented by Microsoft)
$configManagerErrorCodeName = @{
0 = 'This device is working properly'
1 = 'This device is not configured correctly'
2 = 'Windows cannot load the driver for this device'
3 = 'The driver for this device might be corrupted, or your…'
4 = 'This device is not working properly'
5 = 'The driver for this device needs a resource that Windows…'
6 = 'The boot configuration for this device conflicts with other…'
7 = 'Cannot filter'
8 = 'The driver loader for the device is missing'
9 = 'This device is not working properly because the controlling…'
10 = 'This device cannot start'
11 = 'This device failed'
12 = 'This device cannot find enough free resources that it can use'
13 = 'Windows cannot verify this device''s resources'
14 = 'This device cannot work properly until you restart your…'
15 = 'This device is not working properly because there is…'
16 = 'Windows cannot identify all the resources this device uses'
17 = 'This device is asking for an unknown resource type'
18 = 'Reinstall the drivers for this device'
19 = 'Failure using the VxD loader'
20 = 'Your registry might be corrupted'
21 = 'System failure: Try changing the driver for this device'
22 = 'This device is disabled'
23 = 'System failure: Try changing the driver for this device'
24 = 'This device is not present, is not working properly, or does…'
25 = 'Windows is still setting up this device'
26 = 'Windows is still setting up this device'
27 = 'This device does not have valid log configuration'
28 = 'The drivers for this device are not installed'
29 = 'This device is disabled because the firmware of the device…'
30 = 'This device is using an Interrupt Request (IRQ) resource…'
31 = 'This device is not working properly because Windows cannot…'
}
# Lookup table for Availability (values documented by Microsoft)
$availabilityName = @{
1 = 'Other'
2 = 'Unknown'
3 = 'Running/Full Power'
4 = 'Warning'
5 = 'In Test'
6 = 'Not Applicable'
7 = 'Power Off'
8 = 'Off Line'
9 = 'Off Duty'
10 = 'Degraded'
11 = 'Not Installed'
12 = 'Install Error'
13 = 'Power Save - Unknown'
14 = 'Power Save - Low Power Mode'
15 = 'Power Save - Standby'
16 = 'Power Cycle'
17 = 'Power Save - Warning'
18 = 'Paused'
19 = 'Not Ready'
20 = 'Not Configured'
21 = 'Quiesced'
}
Get-CimInstance -ClassName Win32_PnPEntity |
Select-Object -Property @(
'Name'
'Status'
'PNPClass'
'Manufacturer'
'DeviceID'
@{ Name = 'ConfigManagerErrorCode'; Expression = { $configManagerErrorCodeName[[int]$_.ConfigManagerErrorCode] } }
@{ Name = 'Availability'; Expression = { $availabilityName[[int]$_.Availability] } }
)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_PnPEntity |
Select-Object -Property @(
'Name'
'Status'
'PNPClass'
'Manufacturer'
'DeviceID'
'ConfigManagerErrorCode'
)
} 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_PnPEntity
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Availability# | uint16 | read | Availability and status of the device. Values (21)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | Short description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ClassGuid# | string | read | Globally unique identifier (GUID) of this Plug and Play device. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CompatibleID# | string[] | read | A vendor-defined identification string that Setup uses to match a device to an INF file. A device can have a list of compatible IDs associated with it. The compatible IDs should be listed in order of decreasing suitability. If Setup cannot locate an INF file that matches one of a device's hardware IDs, it uses compatible IDs to locate an INF file. A compatible ID has the same format as a HardwareID. For more information, see Windows Driver Kit. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigManagerErrorCode# | uint32 | read | Win32 Configuration Manager error code. Values (32)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigManagerUserConfig# | boolean | read | If TRUE, the device is using a user-defined configuration. 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, the property allows all instances of this class and its subclasses to be uniquely identified. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeviceID# key | string | read | Identifier of the Plug and Play device. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorCleared# | boolean | read | If TRUE, the error reported in LastErrorCode is now cleared. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorDescription# | string | read | More information about the error recorded in LastErrorCode, and information about any corrective actions that may be taken. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HardwareID# | string[] | read | A vendor-defined identification string that Setup uses to match a device to an INF file. Normally, a device has an associated list of hardware IDs. An exception is the 1394 bus driver, which does not use hardware IDs. The first hardware ID in the list should be the device ID. The remaining IDs should be listed in order of decreasing suitability. Hardware IDs appear in one the following formats:
This is the most common format for individual PnP devices. An example of an enumerator is the BIOS or ISAPNP.
An asterisk (*) indicates use by more than one enumerator.
A custom format. Examples of Hardware IDs are: root\*PNPOF08 PC\VEN_1000&DEV_001&SUBSYS_00000000&REV_02 For more information, see the Windows Driver Kit. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Date and time the object was installed. This property does not need a value to indicate that the object is installed. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LastErrorCode# | uint32 | read | Last error code reported by the logical device. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Manufacturer# | string | read | Name of the manufacturer of the Plug and Play device. Example: "Acme" Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Label by which the object is known. When subclassed, the property can be overridden to be a key property. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PNPClass# | string | read | Warning: This property, despite being listed in the MOF file, does not actually exist in the class. The property is described here only for the sake of completeness, and to clarify the MOF file itself. The name of the type of this Plug and Play device. Windows Server 2012 R2, Windows 8.1, Windows Server 2012, Windows 8, Windows Server 2008 R2, Windows 7, Windows Server 2008 and Windows Vista: This property is not in the MOF file. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PNPDeviceID# | string | read | Windows Plug and Play device identifier of the logical device. Example: "*PNP030b" Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PowerManagementCapabilities# | uint16[] | read | Not implemented. Values (8)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PowerManagementSupported# | boolean | read | Not implemented. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Present# | boolean | read | Whether this Plug and Play device is currently in the system. Windows Server 2012 R2, Windows 8.1, Windows Server 2012, Windows 8, Windows Server 2008 R2, Windows 7, Windows Server 2008 and Windows Vista: This property is not supported. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Service# | string | read | Name of the service that supports this Plug and Play device. For more information, see Win32_SystemDriverPnPEntity. Example: "atapi" 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. Values include the following: Values (12)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StatusInfo# | uint16 | read | State of the logical device. If this property does not apply to the logical device, the value 5 (Not Applicable) should be used. Values (5)
Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SystemCreationClassName# key | string | read | Value of the scoping computer's CreationClassName property. Code | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SystemName# key | string | read | Name of the scoping system. Code |
Methods
Disable #
Disables this Plug and Play device.
uint32 Disable([out] boolean rebootNeeded);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| rebootNeeded | boolean | out | Whether a reboot is needed. |
Call the Disable method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PnPEntity -Filter "DeviceID = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Disable'
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
$result.rebootNeeded
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Enable #
Enables this Plug and Play device.
uint32 Enable([out] boolean rebootNeeded);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| rebootNeeded | boolean | out | Whether a reboot is needed. |
Call the Enable method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PnPEntity -Filter "DeviceID = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Enable'
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
$result.rebootNeeded
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
GetDeviceProperties #
Gets the specified properties of this Plug and Play device.
uint32 GetDeviceProperties([in] string[] devicePropertyKeys, [out] Win32_PnPDeviceProperty[] deviceProperties);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| devicePropertyKeys | string[] | in | The properties to return. |
| deviceProperties | Win32_PnPDeviceProperty[] | out | The requested properties in appropriate subtypes of the Win32_PnPDeviceProperty abstract class. |
Call the GetDeviceProperties method
review before running# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_PnPEntity -Filter "DeviceID = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'GetDeviceProperties'
Arguments = @{ devicePropertyKeys = @('Example') }
WhatIf = $true # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters
# With -WhatIf nothing runs and no result is returned
if ($result) {
$result.ReturnValue
$result.deviceProperties
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Declared but not implemented methods: Reset, SetPowerState.
Remarks
The Win32_PnPEntity class is derived from CIM_LogicalDevice.
Inheritance
Superclass chain
- CIM_ManagedSystemElement
- CIM_LogicalElement
- CIM_LogicalDevice
- Win32_PnPEntity
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("{FE28FD98-C875-11d2-B352-00104BC97924}") 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.