I have a call to powershell.exe that looks like this, and which works from my commandline:

powershell.exe -noexit -command " & 'C:\Test\test.ps1' "

However, when I enter that entry exactly that way in the runonce-key of my current user, nothing happens.

What is the correct way to call powershell.exe passing parameters from runonce or run?

有帮助吗?

解决方案

Try with full path:

c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit "C:\Test\test.ps1" 

or

c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command " & 'C:\Test\test.ps1' " 

其他提示

A slightly different approach would be to put all your call to powershell.exe with all arguments / parameters into a simple *.bat file, and call that *.bat file from your RunOnce Key. This way you don't need to play around with params, which can mess-up sometimes. Your PowerShell script could even delete that *.bat file, since it is required only once.

Use the File argument instead of command. You can also use some of the other parameters to clean things up (noprofile, sta, and/or WindowStyle)

This is an example of what I use.

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -sta -WindowStyle Hidden -File "C:\Test\Test.ps1"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top