2015-11-18 25 views
1

我想弄清楚一個腳本,它將幫助我列出安裝在我係統上的所有Microsoft更新。 我使用Powershell列出計算機上的所有微軟更新?

Get-Hotfix 

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

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

這對我有用。 請幫忙。

+0

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

+0

這會不會讓我只是微軟更新或全部,因爲這是我已經做了。 –

+0

運行此操作時看到哪些非Microsoft更新? – sodawillow

回答

0

你可以使用這個腳本(沒有找到一種方式來顯示與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'。 –

相關問題