2

I have a Powershell script to install TCP/IP printers on Windows 10 that uses PNPUTIL to load drivers. When the script is run from a Powershell window, everything works great.

When I launch the script from a shortcut using the format

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1

I get an error 'The term 'pnputil.exe' is not recognized as the name of a cmdlet, function, script file, or operable program' when PNPUTIL is called. The rest of the script runs fine.

Relevant code:

Write-Host `n 'Installing printer driver..'
pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

Any ideas as to why this won't work when launched from a shortcut?

EDIT:I tried using

& pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

as referenced in

Running CMD command in PowerShell

but I still get the error. I also tried

start-process pnputil.exe /add-driver "\\myServer\HP UPD PCL 5\hpcu180t.inf"

but got a similar error that pnputil.exe could not be found.

Both of these options work from a Powershell prompt, but again, fail when launched from a shortcut.

Thank you in advance.

mklement0
  • 382,024
  • 64
  • 607
  • 775

1 Answers1

3

You're invoking a 32-bit instance of PowerShell on a 64-bit system, and that instance doesn't see pnputil.exe (by filename only).

Instead of:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1

use:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file MyScript.PS1
  • Folder C:\Windows\SysWOW64 is where the 32-bit executables live.
  • Paradoxically, for historical reasons, it is C:\Windows\System32 that houses the 64-bit executables.

If, for some reason, you do need to run a 32-bit instance of PowerShell, you can invoke pnputil.exe by its full path:
It only exists as a 64-bit executable in the 64-bit system folder, which 32-bit processes can access as C:\Windows\SysNative:

C:\Windows\SysNative\pnputil.exe
mklement0
  • 382,024
  • 64
  • 607
  • 775