Powershell启动过程 – 参数列表不起作用

Start-Transcript c:\scripts\InstallUpdates.log -Append # -NoClobber $SourceMSUFiles = (get-content install-list.txt | where {$_ -like "*.msu"}) #Install MSU files foreach($file in $SourceMSUFiles) { $Argument= "$Files",' /quiet',' /norestart' & start wusa -ArgumentList @Argument -Wait # -RedirectStandardOutput "c:\scripts\InstallUpdates.log" Write-Host "Installing $file" `n } stop-transcript 

在普通的cmd行中,这个工作就像这样:

 wusa $files /quiet /norestart 

我想使用Powershell来完成我通常使用命令行的function。

实际上你可以使用相同的命令。 或者你是在追求更多的地方性东西? 我认为使用CMD语法启动可执行文件比较容易,除非你看到一些奇怪的错误( KISS )。 即使redirect工作:

 Get-Content install-list.txt | Where-Object {$_ -like "*.msu} | Foreach-Object { wusa $_ /quiet /norestart >> "c:\script\installupdates.log" | Wait-Process } 

当我尝试这个反对假冒更新时,日志文件是空的。 我认为这可能是与安静的select。 在命令行中似乎也很安静!

在PowerShell中,您可以像在CMD中那样调用它。 不需要使用Start-Process

约翰的答案解决了这个问题。

最后的代码

 Get-Content install-list.txt | Where-Object {$_ -like "*.msu"} | Foreach-Object { wusa $_ /quiet /norestart >> "c:\script\installupdates.log" | Wait-Process } Write-Host "Installed patches on" ((get-date -DisplayHint Date)) get-hotfix|where {$_.InstalledOn -gt ((get-Date).AddDays(-1))}|Select HotfixId