foreach powershell循环打开项

时间:2018-05-29 05:21:22

标签: powershell foreach

我有很多文件是windows themepacks,我想打开它们。我不想在列表中双击并双击每个列表。所以我将get-childitem发送到变量$ item然后遍历它,接下来我要打开每个文件。只是使用名称和./windows7.theme有效,但代码并没有。我尝试了下面的不同选项,但他们不能工作,请帮忙。另外,让我知道通过PowerShell打开文件的任何其他方法

foreach($item in $i){$a=$item.name;./$a}
foreach($item in $i){$a=$item.name;./($a)}
foreach($item in $i){./($item.name)}

image of error

2 个答案:

答案 0 :(得分:2)

使用:

invoke-item $a

Invoke-Item cmdlet对指定的项执行默认操作。例如,它运行可执行文件或打开文档 与文档文件类型关联的应用程序中的文件。

更多信息:

get-help invoke-item -full

答案 1 :(得分:1)

或者你可以试试这个

$baselocation  = (Get-Location).Path + "\Desktop\"
$fileExtension = ".txt"
foreach($itm in $var)
{
    &($baselocation+ $itm.name + $fileExtension)
}

我的文件只列出了其他文件的名称,位于C:\ users \ user1 \ Desktop

来源:Invocation Operator

相关问题