它基本上做的是脚本从一个位置获取.msu文件并复制到“C:\ temp \”文件夹。 然后脚本获取所有.msu文件并将名称存储在数组中。 使用foreach循环,它尝试将.msu更新应用于运行脚本的本地服务器。
然而,当我运行脚本时。它没有做任何事情。
以下是代码
$from="sourceLocation\*.msu"
$to="C:\temp\"
Copy-Item $from $to -Recurse -Force
$listOfMSUs= (Get-ChildItem –Path $to -Filter "*.msu").Name
Write-Host $listOfMSUs
if($listOfMSUs)
{
foreach($msu in $listOfMSUs)
{
Write-Host "Processing The Update"
& wusa $to$msu /quiet /norestart
}
}
else{
Write-Host "MSUs doesnt exists"
}
有什么建议吗?
答案 0 :(得分:2)
您正在将文件复制到本地文件夹(C:\temp
),但在远程主机上运行wusa
。该主机可能具有相同的本地文件夹,但您没有将更新复制到该文件夹。如果要从远程主机上的本地文件夹安装更新,则必须将它们复制到远程主机上的该文件夹中:
Copy-Item $from "\\$hostname\$($to -replace ':','$')" -Recurse -Force
编辑:由于您希望在运行脚本的主机上安装更新,因此您的代码应该可以正常运行,尽管我会对其进行简化,例如:像这样:
$from = "sourceLocation\*.msu"
$to = 'C:\temp'
Copy-Item $from $to -Recurse -Force
$updates = @(Get-ChildItem –Path $to -Filter '*.msu')
if ($updates.Count -ge 1) {
$updates | % {
Write-Host "Processing update $($_.Name)."
& wusa $_.FullName /quiet /norestart
}
} else {
Write-Host 'No updates found.'
}
主机上是否启用了UAC?在这种情况下,您需要在手动运行时以“管理员”身份运行脚本,或者在将脚本作为计划任务运行时选中“以最高权限运行”选项。
答案 1 :(得分:2)
答案很简单。我需要的只是一个/ install命令参数。 所以该行应
& wusa /install $to$msu /quiet /norestart
OR
& wusa $to$msu /quiet /norestart