如何从已安装的更新中获取所有详细信息 Window

How to get all details from Installed Updates Window

我想以任何文本格式获取所有这些信息(包括非 windows 更新)... 如果您有任何获取这些信息的方法,请分享。 有关详细信息,请参阅附图...

试试这个方法:

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Updates = $Searcher.QueryHistory(0,$HistoryCount)
$Updates |  Select Title,@{l='Name';e={$($_.Categories).Name}},Date

编辑:

要获取所有更新(仅通过 Windows 更新安装,即使对于第 3 方也是如此)然后将结果导出到文本文件,您可以使用以下脚本:

    $session = [activator]::CreateInstance([type]::GetTypeFromProgID(“Microsoft.Update.Session”,$ComputerName))
    $us = $session.CreateUpdateSearcher()
    $qtd = $us.GetTotalHistoryCount()
    $hot = $us.QueryHistory(0, $qtd)

    # Output object
    $OutPut = @()

    #Iterating and finding updates
    foreach ($Upd in $hot) {

        # 1 means in progress and 2 means succeeded
        if ($Upd.operation -eq 1 -and $Upd.resultcode -eq 2) {
        $OutPut +=  New-Object -Type PSObject -Prop @{
                ‘ComputerName’=$computername
                ‘UpdateDate’=$Upd.date
                ‘KB’=[regex]::match($Upd.Title,’KB(\d+)’)
                ‘UpdateTitle’=$Upd.title
                ‘UpdateDescription’=$Upd.Description
                ‘SupportUrl’=$Upd.SupportUrl
                ‘UpdateId’=$Upd.UpdateIdentity.UpdateId
                ‘RevisionNumber’=$Upd.UpdateIdentity.RevisionNumber
            }
        }
    }

    #Writing updates to a text file
    $OutPut | Out-File -FilePath "C:\output.txt" -Append

较早的回复:

您可以使用来自 Technet 的精彩脚本,而不是创建您自己的脚本:PowerShell script to list all installed Microsoft Windows Updates

由于您想要文本格式的输出,我已经更新了那篇文章中的脚本,以便为文本文件中的所有已安装更新生成输出。一切都是可配置的。检查下面的完整脚本。最后一行是我调用可重用方法并将输出生成到文本文件的地方。您可以根据您的环境更改此文本文件的路径。

    Function Get-MSHotfix
    {
        $outputs = Invoke-Expression "wmic qfe list"
        $outputs = $outputs[1..($outputs.length)]


        foreach ($output in $Outputs) {
            if ($output) {
                $output = $output -replace 'y U','y-U'
                $output = $output -replace 'NT A','NT-A'
                $output = $output -replace '\s+',' '
                $parts = $output -split ' '
                if ($parts[5] -like "*/*/*") {
                    $Dateis = [datetime]::ParseExact($parts[5], '%M/%d/yyyy',[Globalization.cultureinfo]::GetCultureInfo("en-US").DateTimeFormat)
                } elseif (($parts[5] -eq $null) -or ($parts[5] -eq ''))
                {
                    $Dateis = [datetime]1700
                }

                else {
                    $Dateis = get-date([DateTime][Convert]::ToInt64("$parts[5]", 16))-Format '%M/%d/yyyy'
                }
                New-Object -Type PSObject -Property @{
                    KBArticle = [string]$parts[0]
                    Computername = [string]$parts[1]
                    Description = [string]$parts[2]
                    FixComments = [string]$parts[6]
                    HotFixID = [string]$parts[3]
                    InstalledOn = Get-Date($Dateis)-format "dddd d MMMM yyyy"
                    InstalledBy = [string]$parts[4]
                    InstallDate = [string]$parts[7]
                    Name = [string]$parts[8]
                    ServicePackInEffect = [string]$parts[9]
                    Status = [string]$parts[10]
                }
            }
        }
    }

    Get-MSHotfix|Select-Object -Property Computername, KBArticle,InstalledOn, HotFixID, InstalledBy|Format-Table | Out-File -FilePath "D:\output.txt"

最简单的方法

Install-Module PSWindowsUpdate -force
Get-WuHistory

Install-Module 适用于 Posh5。对于较旧的使用巧克力:cinst PSWindowsUpdate.

运行 下面的命令使用powershell。您可以轻松地将 Select-Object 重定向到 out-file

Get-WmiObject -Class Win32_QuickFixEngineering

更多信息请参考Win32_QuickFixEngineering