Powershell not finding PNPUTIL when script launched from shortcut










1















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:WindowsSysWOW64WindowsPowerShellv1.0powershell.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 "\myServerHP UPD PCL 5hpcu180t.inf"


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



EDIT:I tried using



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


as referenced in



Running CMD command in PowerShell



but I still get the error. I also tried



start-process pnputil.exe /add-driver "\myServerHP UPD PCL 5hpcu180t.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.










share|improve this question
























  • Possible duplicate of Running CMD command in PowerShell

    – Harry
    Nov 13 '18 at 22:10











  • try to specify full path to pnputil.exe

    – Mike Twc
    Nov 14 '18 at 4:00















1















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:WindowsSysWOW64WindowsPowerShellv1.0powershell.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 "\myServerHP UPD PCL 5hpcu180t.inf"


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



EDIT:I tried using



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


as referenced in



Running CMD command in PowerShell



but I still get the error. I also tried



start-process pnputil.exe /add-driver "\myServerHP UPD PCL 5hpcu180t.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.










share|improve this question
























  • Possible duplicate of Running CMD command in PowerShell

    – Harry
    Nov 13 '18 at 22:10











  • try to specify full path to pnputil.exe

    – Mike Twc
    Nov 14 '18 at 4:00













1












1








1


1






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:WindowsSysWOW64WindowsPowerShellv1.0powershell.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 "\myServerHP UPD PCL 5hpcu180t.inf"


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



EDIT:I tried using



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


as referenced in



Running CMD command in PowerShell



but I still get the error. I also tried



start-process pnputil.exe /add-driver "\myServerHP UPD PCL 5hpcu180t.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.










share|improve this question
















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:WindowsSysWOW64WindowsPowerShellv1.0powershell.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 "\myServerHP UPD PCL 5hpcu180t.inf"


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



EDIT:I tried using



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


as referenced in



Running CMD command in PowerShell



but I still get the error. I also tried



start-process pnputil.exe /add-driver "\myServerHP UPD PCL 5hpcu180t.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.







powershell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 4:03









mklement0

129k20243275




129k20243275










asked Nov 13 '18 at 20:55









Greyula ReyulaGreyula Reyula

83




83












  • Possible duplicate of Running CMD command in PowerShell

    – Harry
    Nov 13 '18 at 22:10











  • try to specify full path to pnputil.exe

    – Mike Twc
    Nov 14 '18 at 4:00

















  • Possible duplicate of Running CMD command in PowerShell

    – Harry
    Nov 13 '18 at 22:10











  • try to specify full path to pnputil.exe

    – Mike Twc
    Nov 14 '18 at 4:00
















Possible duplicate of Running CMD command in PowerShell

– Harry
Nov 13 '18 at 22:10





Possible duplicate of Running CMD command in PowerShell

– Harry
Nov 13 '18 at 22:10













try to specify full path to pnputil.exe

– Mike Twc
Nov 14 '18 at 4:00





try to specify full path to pnputil.exe

– Mike Twc
Nov 14 '18 at 4:00












1 Answer
1






active

oldest

votes


















1














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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -file MyScript.PS1



use:



C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file MyScript.PS1


  • Folder C:WindowsSysWOW64 is where the 32-bit executables live.

  • Paradoxically, for historical reasons, it is C:WindowsSystem32 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:WindowsSysNative:



C:WindowsSysNativepnputil.exe





share|improve this answer

























  • Glad to hear it, @GreyulaReyula; my pleasure.

    – mklement0
    Nov 14 '18 at 14:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289365%2fpowershell-not-finding-pnputil-when-script-launched-from-shortcut%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -file MyScript.PS1



use:



C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file MyScript.PS1


  • Folder C:WindowsSysWOW64 is where the 32-bit executables live.

  • Paradoxically, for historical reasons, it is C:WindowsSystem32 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:WindowsSysNative:



C:WindowsSysNativepnputil.exe





share|improve this answer

























  • Glad to hear it, @GreyulaReyula; my pleasure.

    – mklement0
    Nov 14 '18 at 14:52















1














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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -file MyScript.PS1



use:



C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file MyScript.PS1


  • Folder C:WindowsSysWOW64 is where the 32-bit executables live.

  • Paradoxically, for historical reasons, it is C:WindowsSystem32 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:WindowsSysNative:



C:WindowsSysNativepnputil.exe





share|improve this answer

























  • Glad to hear it, @GreyulaReyula; my pleasure.

    – mklement0
    Nov 14 '18 at 14:52













1












1








1







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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -file MyScript.PS1



use:



C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file MyScript.PS1


  • Folder C:WindowsSysWOW64 is where the 32-bit executables live.

  • Paradoxically, for historical reasons, it is C:WindowsSystem32 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:WindowsSysNative:



C:WindowsSysNativepnputil.exe





share|improve this answer















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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -file MyScript.PS1



use:



C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file MyScript.PS1


  • Folder C:WindowsSysWOW64 is where the 32-bit executables live.

  • Paradoxically, for historical reasons, it is C:WindowsSystem32 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:WindowsSysNative:



C:WindowsSysNativepnputil.exe






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 14:54

























answered Nov 14 '18 at 4:03









mklement0mklement0

129k20243275




129k20243275












  • Glad to hear it, @GreyulaReyula; my pleasure.

    – mklement0
    Nov 14 '18 at 14:52

















  • Glad to hear it, @GreyulaReyula; my pleasure.

    – mklement0
    Nov 14 '18 at 14:52
















Glad to hear it, @GreyulaReyula; my pleasure.

– mklement0
Nov 14 '18 at 14:52





Glad to hear it, @GreyulaReyula; my pleasure.

– mklement0
Nov 14 '18 at 14:52

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289365%2fpowershell-not-finding-pnputil-when-script-launched-from-shortcut%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto