我正在与自动安装在当前目录的所有更新的脚本如下错误:错误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文件。 –
代码更新: –