Powershell 在foreach循环之后运行启动进程

Powershell 在foreach循环之后运行启动进程,powershell,Powershell,这是我的小脚本,我正在努力工作。它使用cli中的手制动器转换avi。之后,我尝试使用7zip cli压缩文件,我无法使用7zip powershell包。如果我运行整个脚本,它将进入压缩部分并出错。我试着将其作为cmd运行并启动进程。就像它没有完成foreach,只是运行下一个命令。如果我单独运行该命令并运行一个已转换的文件,则该命令可以工作。我错过了什么 在Start process命令中,尝试包含-wait选项,以等待zip操作完成,然后再处理其输出 提示:使用7z.exe开关-mx0(完全

这是我的小脚本,我正在努力工作。它使用cli中的手制动器转换avi。之后,我尝试使用7zip cli压缩文件,我无法使用7zip powershell包。如果我运行整个脚本,它将进入压缩部分并出错。我试着将其作为cmd运行并启动进程。就像它没有完成foreach,只是运行下一个命令。如果我单独运行该命令并运行一个已转换的文件,则该命令可以工作。我错过了什么


在Start process命令中,尝试包含-wait选项,以等待zip操作完成,然后再处理其输出


提示:使用7z.exe开关-mx0(完全不要压缩),这将提高您的速度,因为它不会尝试进一步压缩已经压缩的mp4格式。

我可以在Roberts注释的帮助下,使用-mx=0标志来解决这个问题。谢谢这是一份工作副本

$date = Get-Date -Format yyyy-MM-dd
$filelist = Get-ChildItem C:\dan\VideoConvert\*.avi
$pass = Read-Host -Prompt 'Enter Password for archive:  '
$i = 0
function CopyDelete ()
{
    Copy-Item c:\dan\VideoConvert\"$date.7z" \\ssb.local\shares\temp
    Remove-Item c:\dan\VideoConvert\*.7z
    Remove-Item c:\dan\VideoConvert\*.mp4
}
function Process7z ()
{
    Start-Process "c:\dan\VideoConvert\7z.exe" -ArgumentList "a -t7z -mx=0 C:\dan\VideoConvert\$date.7z c:\dan\VideoConvert\*.mp4 -p$pass" -wait
}
function ProcessVideo ()
{
    ForEach ($file in $filelist)
    {
        $i++
        $oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension;
        $newfile = $file.DirectoryName + "\converted$i.mp4";
        Start-Process "C:\dan\VideoConvert\HandBrakeCLI.exe" -ArgumentList "-i `"$oldfile`" -o `"$newfile`"" -Wait -NoNewWindow
    }   
}
ProcessVideo
Process7z
CopyDelete
这似乎是一个答案:
$date = Get-Date -Format yyyy-MM-dd
$filelist = Get-ChildItem C:\dan\VideoConvert\*.avi
$pass = Read-Host -Prompt 'Enter Password for archive:  '
$i = 0
function CopyDelete ()
{
    Copy-Item c:\dan\VideoConvert\"$date.7z" \\ssb.local\shares\temp
    Remove-Item c:\dan\VideoConvert\*.7z
    Remove-Item c:\dan\VideoConvert\*.mp4
}
function Process7z ()
{
    Start-Process "c:\dan\VideoConvert\7z.exe" -ArgumentList "a -t7z -mx=0 C:\dan\VideoConvert\$date.7z c:\dan\VideoConvert\*.mp4 -p$pass" -wait
}
function ProcessVideo ()
{
    ForEach ($file in $filelist)
    {
        $i++
        $oldfile = $file.DirectoryName + "\" + $file.BaseName + $file.Extension;
        $newfile = $file.DirectoryName + "\converted$i.mp4";
        Start-Process "C:\dan\VideoConvert\HandBrakeCLI.exe" -ArgumentList "-i `"$oldfile`" -o `"$newfile`"" -Wait -NoNewWindow
    }   
}
ProcessVideo
Process7z
CopyDelete