【问题标题】:How to get all details from Installed Updates Window如何从已安装的更新窗口获取所有详细信息
【发布时间】:2016-04-21 06:52:06
【问题描述】:

我想以任何文本格式获取所有这些信息(包括非 Windows 更新)... 如果您有任何方法可以获取这些信息,请分享。 更多详情请看附图...

【问题讨论】:

标签: powershell wmi-query wmic cmdlets


【解决方案1】:

试试这个方法:

$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

【讨论】:

  • 很好,这很好用。我试图过滤掉它,只为重要的更新,但找不到任何东西。你对此有什么建议吗?谢谢!
  • @Sambhav,你当然可以!将 $Updates = $Searcher.QueryHistory(0,$HistoryCount) 更改为 $Updates = $Searcher.Search("IsInstalled=1").Updates |其中 { $_.MsrcSeverity -eq "Important" } 。但请注意,Search 方法的运行速度非常慢。
  • 这太棒了!
【解决方案2】:

编辑:

要获取所有更新(仅通过 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"

【讨论】:

  • 感谢 Aman Sharma,但我想确认一下,我们是否也可以列出非 Windows 产品?使用这个脚本!
  • 没有其他方法可以轻松实现的
  • 正如@majkinetor 提到的,这个和其他答案中提到的任何其他方法只会获取 Windows 更新。
  • @JayPanchal 我已经提供了答案的更新。请尝试这个新脚本。我已经按照你的要求提供了。
【解决方案3】:

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

Get-WmiObject -Class Win32_QuickFixEngineering

请参考Win32_QuickFixEngineering 了解更多信息。

【讨论】:

    【解决方案4】:

    最简单的方法

    Install-Module PSWindowsUpdate -force
    Get-WuHistory
    

    Install-Module 在 Posh5 上工作。对于老年人使用巧克力:cinst PSWindowsUpdate.

    【讨论】:

    • 它是否也列出了非windows更新?虽然我试过了,但我无法获得非windows更新...详情...
    • 没有。我没有看到那部分对不起。那么你需要不同的代码,但这很容易在任何地方找到。
    • 是的!不用担心!顺便感谢您的努力!我会试着深入挖掘它!
    • 无论如何这都是困难的部分,使用上面的代码变得非常容易。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2011-12-15
    • 1970-01-01
    相关资源
    最近更新 更多