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.

2
  • Possible duplicate of Running CMD command in PowerShell Commented Nov 13, 2018 at 22:10
  • try to specify full path to pnputil.exe Commented Nov 14, 2018 at 4:00

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.