Powershell列出计算机上的所有微软更新?

问题描述:

我想弄清楚一个脚本,它将帮助我列出安装在我系统上的所有Microsoft更新。 我使用Powershell列出计算机上的所有微软更新?

Get-Hotfix 

做相同的,但我没有得到期望的结果。也不是:

Get-WmiObject -Class "win32_quickfixengineering" | 
where $_.name = "Microsoft" 

这对我有用。 请帮忙。

+0

http://stackoverflow.com/a/33732971/381149 –

+0

这会不会让我只是微软更新或全部,因为这是我已经做了。 –

+0

运行此操作时看到哪些非Microsoft更新? – sodawillow

你可以使用这个脚本(没有找到一种方式来显示与Get-HotFix描述)。

它列出了Windows注册表的Uninstall键中找到的程序,并且再次匹配$filter字符串的名称。

您可以通过更改$computerName(当前是本地主机)从另一台计算机远程获取此信息。

#store computer name in a variable 
$computerName = $env:COMPUTERNAME 

#store filter string in a variable 
$filter = "KB" 

#declare results array 
$result = @() 

#store registry key paths in an array 
$keyList = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\', 
      'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\' 

#open registry hive HKLM 
$hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $computerName) 

#for each key path 
foreach($key in $keyList) { 

    #open key 
    $uninstallKey = $hive.OpenSubKey($key) 

    #if key has been opened 
    if($uninstallKey) { 

     #list program keys 
     $programList = $uninstallKey.GetSubKeyNames() 

     #for each key 
     foreach($program in $programList) { 

      #get the program name 
      $programName = $uninstallKey.OpenSubKey($program).GetValue("DisplayName") 

      #if the program name is not null and matches our filter 
      if(($programName) -and ($programName -like "*$filter*")) { 

       #add program name to results array 
       $result += $programName 
      } 
     } 
    } 
} 

#sort and output results array 
$result | Sort-Object 
+0

这对我很有用,但是因为我在PowerShell中不太好,你能解释一下这里发生了什么吗? –

+0

我会提供一些解释(我在工作中,我必须找点空闲时间^^) – sodawillow

+0

是的,当然。另外我想知道,为什么过滤器是'KB'。 –