Install a printer driver via powershell script

HinW 20 Reputation points
2023-02-13T08:46:47.3866667+00:00

I would like a PowerShell script that can install a printer driver.

I have a INF file stored in C:\temp\hpPrinter\autorun.inf

I tried below line of code in powershell but get an error saying that.

Code:

pnputil.exe -i -a $infPath

Error:

Microsoft PnP Utility

Adding driver package: autorun.inf

Failed to add driver package: The third-party INF does not contain digital signature information.

Total driver packages: 1

Added driver packages: 0

Thanks

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-03-19T20:09:05.1566667+00:00

    The error you are receiving is because the INF file you are trying to install does not have digital signature information. To bypass this error, you can use the following PowerShell script to install the printer driver:

    $infPath = "C:\temp\hpPrinter\autorun.inf"
    $driverPackage = Get-Item $infPath | Select-Object -ExpandProperty VersionInfo | Select-Object -ExpandProperty FileName
    $driverPackageName = $driverPackage.Substring(0, $driverPackage.IndexOf("."))
    
    # Import the driver package
    pnputil.exe -a $infPath
    
    # Install the driver
    $infPath = "C:\Windows\inf\$driverPackage"
    Add-PrinterDriver -Name $driverPackageName -InfPath $infPath
    
    

    In this script, we first get the name of the driver package from the INF file. Then we use pnputil.exe to import the driver package. Finally, we use Add-PrinterDriver cmdlet to install the driver.

    Please note that this script assumes that the INF file contains the correct driver package name and that you have administrative privileges to install the printer driver.


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.