Displaying and Interacting with Drivers

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
JohnTitor
Posts: 163
Last visit: Tue Jul 27, 2021 5:57 am

Displaying and Interacting with Drivers

Post by JohnTitor »

Hello,

I'm looking for a way to manage drives remotely for the techs

Essentially query the PC, list the drivers, give them easy selections USB, DisplayDrivers, Mouse, etc... remotely remove
Think Device Uninstall in device management but not remove the software

I can't seem the find the best solution that provides me with the cleanest details
for example
when I do

Get-CimInstance win32_PnPSignedDriver | Select-Object Description,DeviceClass,DriverProviderName,DriverVersion,FriendlyName,InfName,Manufacturer | Where-Object {$_.Description -ne $null}

But how do I take the InfName, and perform the Device Uninstall?

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

You can only display installed drivers. There is a folder under windows that contains inf files for drivers that are available for installation. You would have to learn how to read these files. They contain manufacturer model and options for a driver along with the driver binaries list.

The folder is here: C:\Windows\INF

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

Here is what a driver INF looks like. This is the USB print driver file.
  1. [Version]
  2. Signature="$WINDOWS NT$"
  3. Class=USB
  4. ClassGUID={36FC9E60-C465-11CF-8056-444553540000}
  5. Provider=%MSFT%
  6. DriverVer = 06/21/2006,10.0.17763.1
  7.  
  8. [SourceDisksNames]
  9. 3426=windows cd
  10.  
  11. [SourceDisksFiles]
  12. usbprint.sys        = 3426
  13.  
  14. [ControlFlags]
  15. ExcludeFromSelect = *
  16.  
  17. [DestinationDirs]
  18. DefaultDestDir = 12
  19. ; don't need this yet. USBPRINT_Inst.CopyFilesDLL.NT = 11
  20.  
  21. [Manufacturer]
  22. %MSFT%=Microsoft,NTamd64
  23.  
  24. [Microsoft.NTamd64]
  25. %USBPRINT.DeviceDesc% = USBPRINT_Inst,USB\Class_07,GENERIC_USB_PRINTER
  26. %USBPRINT_UNKNOWNPRINTER.DeviceDesc% = NO_DRV, USBPRINT\UnknownPrinter
  27.  
  28. ;=====================================================================
  29. [USBPRINT_Inst.NT]
  30. Copyfiles = USBPRINT_Inst.CopyFiles.NT, USBPRINT_Inst.CopyFilesDLL.NT
  31.  
  32. [USBPRINT_Inst.CopyFiles.NT]
  33. usbprint.sys,,,0x100
  34.  
  35. [USBPRINT_INST.CopyFilesDLL.NT]
  36.  
  37. [USBPRINT_Inst.NT.Services]
  38. AddService = usbprint,0x00000002,USBPRINT_Service_Inst
  39. ;=====================================================================
  40.  
  41. [USBPRINT_Service_Inst]
  42. DisplayName    = %USBPRINT.SvcDesc%
  43. ServiceType    = 1 ;KERNEL_DRIVER
  44. StartType      = 3 ;DEMAND START
  45. ErrorControl   = 1 ;RROR_NORMAL
  46. ServiceBinary  = %12%\usbprint.sys
  47. LoadOrderGroup = extended base
  48.  
  49. ;SPSVCINST_TAGTOFRONT  = 0x00000001
  50. ;SPSVCINST_ASSOCSERVICE= 0x00000002
  51. ;SERVICE_KERNEL_DRIVER = 1
  52. ;SERVICE_BOOT_START    = 0
  53. ;SERVICE_SYSTEM_START  = 1
  54. ;SERVICE_AUTO_START    = 2
  55. ;SERVICE_DEMAND_START  = 3
  56. ;SERVICE_ERROR_NORMAL  = 1
  57. ;SERVICE_ERROR_IGNORE  = 0
  58.  
  59.  
  60. [NO_DRV.NT]
  61.  
  62. [NO_DRV.NT.Services]
  63. AddService = , 2   ; null service install
  64.  
  65.  
  66. [Strings]
  67. ;Non-Localizable
  68. MSFT = "Microsoft"
  69.  
  70. ;Localizable
  71. USBPRINT.DeviceDesc = "USB Printing Support"
  72. USBPRINT_UNKNOWNPRINTER.DeviceDesc = "No Printer Attached"
  73. USBPRINT.SvcDesc = "Microsoft USB PRINTER Class"

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

You cannot easily mange devices remotely. The closest you can come is with the PNP WMI classes.

Win32_PnPDevice
Win32_PnPEntity
Win32_PnPSignedDriver
Win32_PnPDeviceProperty


Also:
Get-WmiObject -list WIn32_PnP*

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

Also review the following:

Get-WmiObject -list Win32_Systemd*

Note that these classes only work with installed drivers and devices. THey cannot discover uninstalled drivers and devices like we see in DeviceManager. The DM APIs can be found in the Windows Hardware Dev Center .

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

Here is one thing I just thought of. FOr PnP devices that have been plugged in and have not automatically been installed we can find them like this:

Code: Select all

Get-WmiObject Win32_PNPEntity | 
      Where-Object{$_.ConfigManagerErrorCode -ne 0} | 
      Select Name, DeviceID, ConfigManagerErrorCode
The error codes are here: https://support.microsoft.com/en-us/hel ... in-windows

User avatar
JohnTitor
Posts: 163
Last visit: Tue Jul 27, 2021 5:57 am

Re: Displaying and Interacting with Drivers

Post by JohnTitor »

The way we do it in our environment say we want to remove the display driver

Go to device management
Find the display adapter
Right click and choose uninstall
We make sure that “delete associated software” is uncheck
And reboot the machine
Upon logging in, Windows finds the device and installs it.

That’s what I’m looking to do.

jvierra
Posts: 14876
Last visit: Fri Jul 30, 2021 8:16 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Displaying and Interacting with Drivers

Post by jvierra »

Can't do that with PowerShell.

You can remove th device with WMI. Get the device and remove it.

User avatar
JohnTitor
Posts: 163
Last visit: Tue Jul 27, 2021 5:57 am

Re: Displaying and Interacting with Drivers

Post by JohnTitor »

Sweet. I’ll look into that and post back.

User avatar
JohnTitor
Posts: 163
Last visit: Tue Jul 27, 2021 5:57 am

Re: Displaying and Interacting with Drivers

Post by JohnTitor »

After some more time researching I’ve discovered MS isn’t letting us do this without devcon

Locked