我有一个包含如下值的数组:
C:\DIR1\FILE1
C:\DIR1\FILE2
C:\DIR2\FILE1
C:\DIR2\FILE2
我需要按如下方式执行程序:
EXECUTABLE.exe C:\DIR1 C:\VARDIR FILE1 FILE2
EXECUTABLE.exe C:\DIR2 C:\VARDIR FILE1 FILE2
我尝试创建一个foreach循环,但这将执行四次,而不是两次。
答案 0 :(得分:-1)
删除'Write-Host'以运行EXECUTABLE.exe
$arr = 'C:\DIR1\FILE1', 'C:\DIR1\FILE2', 'C:\DIR2\FILE1', 'C:\DIR2\FILE2'
$arr | group {Split-Path $_} | ? count -eq 2 | % {
$arg1 = Split-Path $_.group[0]
$arg2 = Split-Path $_.group[0] -Leaf
$arg3 = Split-Path $_.group[1] -Leaf
Write-Host EXECUTABLE.exe $arg1 "C:\VARDIR" $arg2 $arg3
}