Pergunta

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?

Foi útil?

Solução

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' " 

Outras dicas

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"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top