Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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 - Fatal编程技术网

Powershell逐个执行文件

Powershell逐个执行文件,powershell,Powershell,我想用exe一个接一个地执行几个文件。为此,我使用带有Out Gridview的Get ChildItem,并将其放入变量中,以选择稍后要运行的文件: $choose = Get-ChildItem 'path' | Out-GridView -Title "Select your files" -OutputMode Multiple 要逐个运行所有文件,我想我应该使用以下代码: $choose | Foreach-Object{ xexec

我想用exe一个接一个地执行几个文件。为此,我使用带有Out Gridview的Get ChildItem,并将其放入变量中,以选择稍后要运行的文件:

$choose = Get-ChildItem 'path' | 
          Out-GridView -Title "Select your files" -OutputMode Multiple
要逐个运行所有文件,我想我应该使用以下代码:

$choose |
Foreach-Object{
    xexec $choose
xexec
是可执行文件的名称,但它不起作用。它只执行选定文件中的第一个文件


我不明白为什么。

ForEach Object
主体中,您将希望使用
$\ucode>(或
$PSItem
)自动变量引用当前管道项目:

$choose | Foreach-Object { xexec $_.FullName }

首先,循环缺少右大括号。第二个$choose是您试图循环的整个列表,您绝对不应该在循环中引用它。因为它是一个foreach对象循环,所以您需要引用$或$psitem