Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell将焦点设置在新窗口上_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

Powershell将焦点设置在新窗口上

Powershell将焦点设置在新窗口上,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,我希望在从脚本启动的新窗口上运行命令,如下所示: function start() { start-process powershell; echo "test"; } 此命令启动新的powershell窗口,但echo“test”在旧窗口中运行,我可以在新窗口中运行命令吗?我正在运行Win7/64位,Powershell V4.0 当我使用 function start() { echo "test" | start powershell; } 我明白了 sta

我希望在从脚本启动的新窗口上运行命令,如下所示:

function start() {

    start-process powershell; echo "test";


}
此命令启动新的powershell窗口,但
echo“test”
在旧窗口中运行,我可以在新窗口中运行命令吗?我正在运行Win7/64位,Powershell V4.0

当我使用

function start() {

    echo "test" | start powershell;


}
我明白了

start-process : The input object cannot be bound to any parameters for the command either because the command does not
take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At C:\Users\Bane\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:50 char:15
+ echo "test" | start-process powershell;
+               ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (test:PSObject) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StartProcessCommand

它打开新窗口,但命令未运行。

With
实际上是单独运行这些命令。相反,请使用
-ArgumentList
命令选项提供要执行的命令或脚本,如下所示

start-process powershell.exe -wait -verb open -ArgumentList "echo Test test";
因此,您的代码应该如下所示

function start() 
{
 start-process powershell.exe -wait -verb open -ArgumentList "echo Test test";
}

请后退一步,描述您的问题,而不是您认为的解决方案。通过这样做,您最终想要实现什么?首先,您应该阅读powershell的基础知识:
用于分隔命令,
|
是管道操作符,它将前面函数的输出转发给后面的函数。如果您想在powershell中学习,我建议您直接使用
get help
cmdlete我需要的xD。
$args = '-noexit -command "echo test"'
Start-Process powershell -ArgumentList $args