开发者

Executing a scriptblock via startprocess

开发者 https://www.devze.com 2023-04-02 12:53 出处:网络
Would any of you possibly know why this is not working? Start-Process $PSHOME\\powershell.exe -ArgumentList \"-NoExit -Command & `\"{$outvar1 = 4+4; `\"out: $outvar1`\"}`\"\" -Wait

Would any of you possibly know why this is not working?

Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit -Command & `"{$outvar1 = 4+4; `"out: $outvar1`"}`"" -Wait

The ultimate purpose for this is so that i can run a script block as another user with the addition of the -Credential option. But i can not get this simpl开发者_JAVA技巧e script block to work yet. Many thanks. Chris.


Here is somthing that is working:

PS C:\> Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit","-Command  `"&{`$outvar1 = 4+4; `"write-output `$outvar1`"}`"" -Wait

-ArgumentList is an array of strings $outvar is interpreted so I use `$outvar

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号