如何远程或本地查看计算机上所有已安装程序与软件?
完整获取已安装软件的PowerShell方案及替代方法
一、覆盖全场景的PowerShell脚本
之前的命令仅覆盖了部分注册表路径,导致遗漏用户级安装、32位软件等内容。下面的脚本会扫描所有常见软件注册位置,并自动去重输出:
# 定义需要扫描的注册表路径 $regPaths = @( "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ) # 收集所有安装信息 $installedSoftware = foreach ($path in $regPaths) { if (Test-Path $path) { Get-ChildItem $path | ForEach-Object { $displayName = $_.GetValue('DisplayName') $displayVersion = $_.GetValue('DisplayVersion') $publisher = $_.GetValue('Publisher') if (![string]::IsNullOrWhiteSpace($displayName)) { [PSCustomObject]@{ DisplayName = $displayName DisplayVersion = $displayVersion Publisher = $publisher RegistryPath = $path } } } } } # 去重并输出(按软件名称分组,保留版本最新的项) $installedSoftware | Group-Object -Property DisplayName | ForEach-Object { $_.Group | Sort-Object -Property DisplayVersion -Descending | Select-Object -First 1 } | Format-Table DisplayName, DisplayVersion, Publisher -AutoSize
这个脚本解决了常见遗漏问题:
- 扫描32位软件对应的
Wow6432Node注册表分支 - 扫描当前用户(HKCU)安装的软件(部分软件仅对当前用户可见)
- 过滤空的软件名称,避免无效项
- 自动去重同一软件的重复注册项
二、远程检查的实现方式
1. 使用Invoke-Command远程执行脚本
若目标机器开启WinRM服务(域环境默认开启,工作组需手动配置),可直接远程运行上述脚本:
$computerName = "远程机器名或IP" $credential = Get-Credential # 输入远程机器的有权限账户 Invoke-Command -ComputerName $computerName -Credential $credential -ScriptBlock { $regPaths = @( "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall", "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ) $installedSoftware = foreach ($path in $regPaths) { if (Test-Path $path) { Get-ChildItem $path | ForEach-Object { $displayName = $_.GetValue('DisplayName') $displayVersion = $_.GetValue('DisplayVersion') $publisher = $_.GetValue('Publisher') if (![string]::IsNullOrWhiteSpace($displayName)) { [PSCustomObject]@{ DisplayName = $displayName DisplayVersion = $displayVersion Publisher = $publisher RegistryPath = $path } } } } } $installedSoftware | Group-Object -Property DisplayName | ForEach-Object { $_.Group | Sort-Object -Property DisplayVersion -Descending | Select-Object -First 1 } } | Format-Table DisplayName, DisplayVersion, Publisher -AutoSize
2. 替代方法:使用Get-CimInstance(规避Win32_Product风险)
Win32_Product类不仅遗漏软件,还会触发MSI安装包修复操作,风险较高。推荐用Win32_RegistryValue结合注册表路径远程查询:
$computerName = "远程机器名或IP" $regPaths = @( "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ) foreach ($path in $regPaths) { Get-CimInstance -ComputerName $computerName -ClassName Win32_RegistryValue -Filter "KeyPath='$path' and ValueName='DisplayName'" | ForEach-Object { $version = Get-CimInstance -ComputerName $computerName -ClassName Win32_RegistryValue -Filter "KeyPath='$($_.KeyPath)' and ValueName='DisplayVersion'" [PSCustomObject]@{ DisplayName = $_.Value DisplayVersion = if ($version) { $version.Value } else { "未知" } RegistryPath = "\\$computerName\HKLM\$path" } } } | Group-Object DisplayName | ForEach-Object { $_.Group | Select-Object -First 1 } | Format-Table -AutoSize
三、补充说明
- 绿色软件(无需安装直接运行)不会写入注册表,无法通过上述方法检测,可扫描
Program Files、Program Files (x86)等目录补充查找。 - 远程检查需要目标机器的管理员权限,工作组环境可通过
Enable-PSRemoting命令开启WinRM服务。 - 扫描HKCU路径时,远程执行仅针对当前登录用户的注册表,若要获取所有用户的HKCU内容,需加载对应用户的注册表 hive,操作相对复杂,优先扫描HKLM路径可覆盖全局安装的软件。
内容的提问来源于stack exchange,提问作者Domadea
相关产品推荐
相关产品推荐

