Get PnpDevice - PowerShell


Overview

Get-PnpDevice retrieves information about Plug and Play (PnP) devices connected to the local or remote computer. It provides detailed hardware details such as device name, type, status, manufacturer, and driver information.

Syntax

Get-PnpDevice [-Class <string>] [-DeviceID <string>] [-Name <string>] [-FriendlyName <string>] [-ServiceName <string>] [-PowerState <uint>] [-AssignedDriver <string>] [-All <bool>] [-MaxCount <int>] [-Status <int>] [-Connected <bool>] [-DeviceState <int>] [-DeviceProperty <string>] [-Location <string>] [-LoadDrivers <bool>] [-TolerateErrors <bool>]

Options/Flags

  • -Class: Filter devices by class GUID.
  • -DeviceID: Filter devices by device ID.
  • -Name: Filter devices by device name.
  • -FriendlyName: Filter devices by friendly name.
  • -ServiceName: Filter devices by service name.
  • -PowerState: Retrieve only devices in a specific power state (0: Unknown, 1: D0 Active, 2: D1 Standby, 3: D2 Sleep, 4: D3 Hibernate, 5: D4 Off).
  • -AssignedDriver: Filter devices by assigned driver.
  • -All: Include all devices, even hidden and disconnected ones.
  • -MaxCount: Limit the number of devices returned.
  • -Status: Filter devices by status code (0: OK, 1: Error, 2: Disabled).
  • -Connected: Filter devices by their connection state (True/False).
  • -DeviceState: Filter devices by device state (0: Unknown, 1: Active, 2: Disabled, 3: NotPresent).
  • -DeviceProperty: Retrieve only specified device property (e.g., “HardwareID”, “Mfg”).
  • -Location: Filter devices by their location.
  • -LoadDrivers: Load device drivers before retrieving device information.
  • -TolerateErrors: Continue executing even when errors occur.

Examples

  • Retrieve information about all connected USB devices:
Get-PnpDevice -Class USB
  • Get device details by name:
Get-PnpDevice -Name "Realtek Audio"
  • Filter devices by status:
Get-PnpDevice -Status 1
  • Retrieve only connected devices:
Get-PnpDevice -Connected True
  • Get device location and driver information:
Get-PnpDevice -All -DeviceProperty "Location", "AssignedDriver"

Common Issues

  • Missing device information: Ensure that device drivers are loaded using -LoadDrivers or manually before running the command.
  • Access denied: Use Run as Administrator if the command requires elevated privileges.

Integration

  • Use with Get-ChildItem: Retrieve device files and folders: Get-ChildItem (Get-PnpDevice -Name "My Device")
  • Use in scripts: Automate device management tasks, such as driver updates or power management.
  • Get-PnpDriver
  • Set-PnpDevice