0

最近,由于 WMI 存储库损坏,我公司的 SCCM 部署出现问题,我们找到了一篇知识库文章来解决此问题,但我们需要将其部署到已在该领域的 700 多个系统。我们决定最好的解决方案是通过 GPO Powershell 部署知识库文章。我已经调整了下面的一些代码,但是当 GPO 运行时它什么都不做。当我们单独运行它时,它会提示 wusa 错误,提供使用 wusa 的选项并失败。

有人可以浏览代码,看看我错过了什么导致失败吗?

我当然愿意接受可以清理代码的建议。

变量

$path - 运行directy 脚本。\systemname\Sources\Software\WMI HotFix\

$msu - 当前窗口更新

$update - 被“-”溢出的文件名数组

$kbart - 当前更新 KB 名称

$Hotfix - 安装检查期间返回的结果

$command - 安装更新的命令

$parameters - 命令加上安装命令 '\quiet \norestart' 的参数

$install - 开始安装的过程

$OS - 当前操作系统版本

$folder - 包含 udpates 的路径下的当前文件夹。

kb2617858\win7\x64

kb2617858\win7\x86

Set-ExecutionPolicy RemoteSigned

function Install-MSU($path)
{    

# spilt file name to get KB artical number
$update = $msu.Name -Split'-'
$kbart = $update[1]

# check if update is already installed
$HotFix = Get-HotFix -id $kbart -ea 0

# run if update is not installed
if($HotFix -eq $null)
    {
    Write-Host "Installing $kbart"
    $command = "`"" + "$path\$msu" + "`""
    $parameters = $command + " \quiet \norestart"
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    }

# run if update is installed
else
    {
    Write-Host "Update $kbart installed"
    }
}
} 
# set $path to network share directory location
$path = "\\systemname\Sources\Software\HotFixes"

# set $OS to current OS
$OS = gwmi -query "select Caption, OSArchitecture from win32_OperatingSystem"

# Win7 x86 or x64
if($OS.Caption -match 'Windows 7')
{
if($OS.OSArchitecture -match '64-bit')
{
$folder = 'kb2617858\win7\x64'
$path = "$path\$folder"
Install-MSU($path)
}
else
{
$folder = "kb2617858\win7\x86"
$path = "$path\$folder"
Install-MSU($path)
}
}
else
{

}

先感谢您!!

4

2 回答 2

0
Set-ExecutionPolicy RemoteSigned

function Install-MSU($path) {
    # spilt file name to get KB artical number
    $update = $msu.Name -Split'-'
    $kbart = $update[1]

    # check if update is already installed
    $HotFix = Get-HotFix -id $kbart -ea 0

    # run if update is not installed
    if($HotFix -eq $null){
        Write-Host "Installing $kbart"
        $command = "`"" + "$path\$msu" + "`""
        $parameters = $command + " \quiet \norestart"
        $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
        $install.WaitForExit()
    } else {
    # run if update is installed
        Write-Host "Update $kbart installed"
    }
}

# set $path to network share directory location
$path = "\\systemname\Sources\Software\HotFixes"

# set $OS to current OS
$OS = gwmi -query "select Caption, OSArchitecture from win32_OperatingSystem"

# Win7 x86 or x64
if($OS.Caption -match 'Windows 7'){
    if($OS.OSArchitecture -match '64-bit'){
        $folder = 'kb2617858\win7\x64'
        $path = "$path\$folder"
        Install-MSU($path)
    } else {
        $folder = "kb2617858\win7\x86"
        $path = "$path\$folder"
        Install-MSU($path)
    }
}
于 2015-05-04T21:15:13.170 回答
0

我已经解决了我自己的问题。当参数应该是 /quiet 和 /norestart 时,我没有注意到我正在使用 \quiet 和 \norestart。

如果将来有人需要,下面是最终脚本。

变量

$path - 运行directy 脚本。\\systemname\Sources\Software\WMI HotFix\

$msu - 当前窗口更新

$update - 被“-”溢出的文件名数组

$kbart - 当前更新 KB 名称

$Hotfix - 安装检查期间返回的结果

$command - 安装更新的命令

$parameters - 命令加上安装命令 '\quiet \norestart' 的参数

$install - 开始安装的过程

$OS - 当前操作系统版本

$folder - 包含 udpates 的路径下的当前文件夹。

kb2617858\win7\x64

kb2617858\win7\x86

Set-ExecutionPolicy RemoteSigned

function Install-MSU($path)
{    

# get updates in folders
$msus = ls -Path $path *.msu -Recurse

# loop through updates
foreach ($msu in $msus)
{

# spilt file name to get KB artical number
$update = $msu.Name -Split'-'
$kbart = $update[1]

# check if update is already installed
$HotFix = Get-HotFix -id $kbart -ea 0

# run if update is not installed
if($HotFix -eq $null)
    {
    Write-Host "Installing $kbart"
    $command = "`"" + "$path\$msu" + "`""
    $parameters = $command + " /quiet /norestart"
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    }

# run if update is installed
else
    {
    Write-Host "Update $kbart installed"
    }
    }
}

# set $path to network share directory location
$path = "\\servername\Sources\Software\HotFixes"

# set $OS to current OS
$OS = gwmi -query "select Caption, OSArchitecture from win32_OperatingSystem"

 # if OS is windows 7
if($OS.Caption -match 'Windows 7')
{
if($OS.OSArchitecture -match '64-bit')
{
$folder = 'kb2617858\win7\x64'
$path = "$path\$folder"
Install-MSU($path)
}
else
{
$folder = "kb2617858\win7\x86"
$path = "$path\$folder"
Install-MSU($path)
}
}
else
{

}
于 2015-05-08T19:24:08.883 回答