Displaying and Interacting with Drivers

Ask your Windows 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: 153
Joined: Fri Nov 17, 2017 8:49 pm

Displaying and Interacting with Drivers

Post by JohnTitor » Wed Mar 20, 2019 9:47 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 10:13 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 10:19 am

Here is what a driver INF looks like. This is the USB print driver file.
  1. [Version]
  2.  
  3. Signature="$WINDOWS NT$"
  4.  
  5. Class=USB
  6.  
  7. ClassGUID={36FC9E60-C465-11CF-8056-444553540000}
  8.  
  9. Provider=%MSFT%
  10.  
  11. DriverVer = 06/21/2006,10.0.17763.1
  12.  
  13.  
  14.  
  15. [SourceDisksNames]
  16.  
  17. 3426=windows cd
  18.  
  19.  
  20.  
  21. [SourceDisksFiles]
  22.  
  23. usbprint.sys        = 3426
  24.  
  25.  
  26.  
  27. [ControlFlags]
  28.  
  29. ExcludeFromSelect = *
  30.  
  31.  
  32.  
  33. [DestinationDirs]
  34.  
  35. DefaultDestDir = 12
  36.  
  37. ; don't need this yet. USBPRINT_Inst.CopyFilesDLL.NT = 11
  38.  
  39.  
  40.  
  41. [Manufacturer]
  42.  
  43. %MSFT%=Microsoft,NTamd64
  44.  
  45.  
  46.  
  47. [Microsoft.NTamd64]
  48.  
  49. %USBPRINT.DeviceDesc% = USBPRINT_Inst,USB\Class_07,GENERIC_USB_PRINTER
  50.  
  51. %USBPRINT_UNKNOWNPRINTER.DeviceDesc% = NO_DRV, USBPRINT\UnknownPrinter
  52.  
  53.  
  54.  
  55. ;=====================================================================
  56.  
  57. [USBPRINT_Inst.NT]
  58.  
  59. Copyfiles = USBPRINT_Inst.CopyFiles.NT, USBPRINT_Inst.CopyFilesDLL.NT
  60.  
  61.  
  62.  
  63. [USBPRINT_Inst.CopyFiles.NT]
  64.  
  65. usbprint.sys,,,0x100
  66.  
  67.  
  68.  
  69. [USBPRINT_INST.CopyFilesDLL.NT]
  70.  
  71.  
  72.  
  73. [USBPRINT_Inst.NT.Services]
  74.  
  75. AddService = usbprint,0x00000002,USBPRINT_Service_Inst
  76.  
  77. ;=====================================================================
  78.  
  79.  
  80.  
  81. [USBPRINT_Service_Inst]
  82.  
  83. DisplayName    = %USBPRINT.SvcDesc%
  84.  
  85. ServiceType    = 1 ;KERNEL_DRIVER
  86.  
  87. StartType      = 3 ;DEMAND START
  88.  
  89. ErrorControl   = 1 ;RROR_NORMAL
  90.  
  91. ServiceBinary  = %12%\usbprint.sys
  92.  
  93. LoadOrderGroup = extended base
  94.  
  95.  
  96.  
  97. ;SPSVCINST_TAGTOFRONT  = 0x00000001
  98.  
  99. ;SPSVCINST_ASSOCSERVICE= 0x00000002
  100.  
  101. ;SERVICE_KERNEL_DRIVER = 1
  102.  
  103. ;SERVICE_BOOT_START    = 0
  104.  
  105. ;SERVICE_SYSTEM_START  = 1
  106.  
  107. ;SERVICE_AUTO_START    = 2
  108.  
  109. ;SERVICE_DEMAND_START  = 3
  110.  
  111. ;SERVICE_ERROR_NORMAL  = 1
  112.  
  113. ;SERVICE_ERROR_IGNORE  = 0
  114.  
  115.  
  116.  
  117.  
  118.  
  119. [NO_DRV.NT]
  120.  
  121.  
  122.  
  123. [NO_DRV.NT.Services]
  124.  
  125. AddService = , 2   ; null service install
  126.  
  127.  
  128.  
  129.  
  130.  
  131. [Strings]
  132.  
  133. ;Non-Localizable
  134.  
  135. MSFT = "Microsoft"
  136.  
  137.  
  138.  
  139. ;Localizable
  140.  
  141. USBPRINT.DeviceDesc = "USB Printing Support"
  142.  
  143. USBPRINT_UNKNOWNPRINTER.DeviceDesc = "No Printer Attached"
  144.  
  145. USBPRINT.SvcDesc = "Microsoft USB PRINTER Class"

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 10:27 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 10:32 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 10:50 am

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: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Displaying and Interacting with Drivers

Post by JohnTitor » Wed Mar 20, 2019 3:11 pm

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Displaying and Interacting with Drivers

Post by jvierra » Wed Mar 20, 2019 3:38 pm

Can't do that with PowerShell.

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

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Displaying and Interacting with Drivers

Post by JohnTitor » Wed Mar 20, 2019 3:56 pm

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

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Displaying and Interacting with Drivers

Post by JohnTitor » Wed Mar 20, 2019 10:15 pm

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

Locked