我试图弄清楚一个脚本,它将帮助我列出我系统上安装的所有Microsoft更新。 我正在使用
Get-Hotfix
做同样的事情,但我没有得到理想的结果。两者都不是:
Get-WmiObject -Class "win32_quickfixengineering" |
where $_.name = "Microsoft"
这对我有用。
请帮忙。
答案 0 :(得分: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