我正在與自動安裝在當前目錄的所有更新的腳本如下錯誤:錯誤PowerShell腳本
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:15 char:25
+ $command = "Expand â€「F:* '" + $msu.fullname + "' '" + $PSScr ...
+ ~~~
Unexpected token 'F:*' in expression or statement.
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:29 char:82
+ ... = "Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase"
+ ~
The string is missing the terminator: ".
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:13 char:5
+ {
+ ~
Missing closing '}' in statement block or type definition.
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:10 char:1
+ {
+ ~
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
這裏是代碼體:
{
$msu = get-childitem -path $PSScriptRoot -Recurse | where ($_.extension -eq ".msu") | select fullname
foreach($package in $msu)
{
write-debug $msu.fullname
$command = "Expand –F:* '" + $msu.fullname + "' '" + $PSScriptRoot + "'"
write-debug $command
Invoke-Expression $command
}
$updates = get-childitem -path $PSScriptRoot -Recurse | where ($_.extension -eq ".cab") | select fullname
foreach($update in $updates)
{
write-debug $update.fullname
$command = "dism /online /add-package /packagepath:'" + $update.fullname + "'"
write-debug $command
Invoke-Expression $command
}
$command = "Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase"
Invoke-Expression $command
}
當保存腳本文件因爲UTF-8使用帶** BOM **的UTF-8。 – PetSerAl
謝謝。該腳本正常工作,但我收到另一個錯誤。該腳本不會擴展目錄中的任何msu文件。 –
代碼更新: –