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?

User avatar
jvierra
Posts: 13804
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

User avatar
jvierra
Posts: 13804
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.

Code: Select all

[Version]
Signature="$WINDOWS NT$"
Class=USB
ClassGUID={36FC9E60-C465-11CF-8056-444553540000}
Provider=%MSFT%
DriverVer = 06/21/2006,10.0.17763.1

[SourceDisksNames]
3426=windows cd

[SourceDisksFiles]
usbprint.sys = 3426

[ControlFlags]
ExcludeFromSelect = *

[DestinationDirs]
DefaultDestDir = 12
; don't need this yet. USBPRINT_Inst.CopyFilesDLL.NT = 11

[Manufacturer]
%MSFT%=Microsoft,NTamd64

[Microsoft.NTamd64]
%USBPRINT.DeviceDesc% = USBPRINT_Inst,USB\Class_07,GENERIC_USB_PRINTER
%USBPRINT_UNKNOWNPRINTER.DeviceDesc% = NO_DRV, USBPRINT\UnknownPrinter

;=====================================================================
[USBPRINT_Inst.NT]
Copyfiles = USBPRINT_Inst.CopyFiles.NT, USBPRINT_Inst.CopyFilesDLL.NT

[USBPRINT_Inst.CopyFiles.NT]
usbprint.sys,,,0x100

[USBPRINT_INST.CopyFilesDLL.NT]

[USBPRINT_Inst.NT.Services]
AddService = usbprint,0x00000002,USBPRINT_Service_Inst
;=====================================================================

[USBPRINT_Service_Inst]
DisplayName = %USBPRINT.SvcDesc%
ServiceType = 1 ;KERNEL_DRIVER
StartType = 3 ;DEMAND START
ErrorControl = 1 ;RROR_NORMAL
ServiceBinary = %12%\usbprint.sys
LoadOrderGroup = extended base

;SPSVCINST_TAGTOFRONT = 0x00000001
;SPSVCINST_ASSOCSERVICE= 0x00000002
;SERVICE_KERNEL_DRIVER = 1
;SERVICE_BOOT_START = 0
;SERVICE_SYSTEM_START = 1
;SERVICE_AUTO_START = 2
;SERVICE_DEMAND_START = 3
;SERVICE_ERROR_NORMAL = 1
;SERVICE_ERROR_IGNORE = 0


[NO_DRV.NT]

[NO_DRV.NT.Services]
AddService = , 2 ; null service install


[Strings]
;Non-Localizable
MSFT = "Microsoft"

;Localizable
USBPRINT.DeviceDesc = "USB Printing Support"
USBPRINT_UNKNOWNPRINTER.DeviceDesc = "No Printer Attached"
USBPRINT.SvcDesc = "Microsoft USB PRINTER Class"

User avatar
jvierra
Posts: 13804
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*

User avatar
jvierra
Posts: 13804
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 .

User avatar
jvierra
Posts: 13804
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.

User avatar
jvierra
Posts: 13804
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