首页 > 解决方案 > 使用 PowerShell 将 PC 名称和所需的更新从 WSUS 导出到 CSV

问题描述

我正在尝试使用 PowerShell 从 WSUS 导出 CSV 文件,其中包含需要更新的所有计算机的列表以及每台特定计算机所需的更新的标题或 KB。像这样的东西...

计算机 1、更新 1、更新 2

计算机 2、更新 1、更新 3、更新 5

计算机 3、更新 2、更新 4

我在 TechNet 上找到了这个脚本,它返回计算机名称和需要多少更新,但它不返回更新的标题,它可能会返回 WSUS 中的所有计算机,而不仅仅是需要更新的计算机(我是在目前只有一台计算机的测试环境中)。

Function Get-WSUSClientNeeded {
    [cmdletbinding()]
    Param (
        [parameter(Mandatory=$true)]
        [string]$WsusServer
    )
    #Load assemblies
    [void][system.reflection.assembly]::LoadWithPartialName('Microsoft.UpdateServices.Administration')
    #Connect to WSUS
    $Global:wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($WsusServer,$False,8530)
    #Create Scope objects
    $computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
    $updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
    #Get Update Summary
    $wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) | ForEach {
       New-Object PSObject -Property @{
           ComputerName = ($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName
           NeededCount = ($_.DownloadedCount + $_.NotInstalledCount)
           DownloadedCount = $_.DownloadedCount
           NotApplicableCount = $_.NotApplicableCount
           NotInstalledCount = $_.NotInstalledCount
           InstalledCount = $_.InstalledCount
           FailedCount = $_.FailedCount
       }
    }
}

Get-WSUSClientNeeded -WsusServer 'Server' | Select ComputerName, NeededCount

我对 PowerShell 非常陌生,因此将不胜感激任何帮助。

谢谢!

标签: powershell

解决方案


事实证明这比预期的要容易得多。

Get-WindowsUpdate -WindowsUpdate

Get-WindowsUpdate将从在线来源返回可用更新。-WindowsUpdate参数将从 WSUS 返回更新。确保首先导入 PSWindowsUpdate 模块。


推荐阅读