通过startprocess执行脚本块 [英] Executing a scriptblock via startprocess

查看:81
本文介绍了通过startprocess执行脚本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们中的任何人都可能知道为什么这不起作用吗?

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

此操作的最终目的是使我可以通过添加-Credential选项以另一个用户身份运行脚本块.但是我不能让这个简单的脚本块起作用.非常感谢.克里斯.

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 simple script block to work yet. Many thanks. Chris.

推荐答案

这里正在起作用:

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

-ArgumentList是一个字符串数组$ outvar被解释,所以我使用`$ outvar

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

这篇关于通过startprocess执行脚本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆