Windows
如何通過 Powershell 獲取所有已安裝軟體的完整列表?
我試圖弄清楚如何在 Windows 10 上的 Powershell 中查看所有已安裝軟體的版本號。我挖了一個範例,但是當我將生成的列表與Control Panel > Uninstall a Program中的內容進行比較時,它似乎不完整。例如,查詢輸出中缺少 Google Chrome。知道為什麼嗎?我對 Powershell 的經驗很少,所以也許有些明顯?
Get-WMIObject -Query "SELECT * FROM Win32_Product" |FT
嘗試這個:
function Get-InstalledApps { param ( [Parameter(ValueFromPipeline=$true)] [string[]]$ComputerName = $env:COMPUTERNAME, [string]$NameRegex = '' ) foreach ($comp in $ComputerName) { $keys = '','\Wow6432Node' foreach ($key in $keys) { try { $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $comp) $apps = $reg.OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames() } catch { continue } foreach ($app in $apps) { $program = $reg.OpenSubKey("SOFTWARE$key\Microsoft\Windows\CurrentVersion\Uninstall\$app") $name = $program.GetValue('DisplayName') if ($name -and $name -match $NameRegex) { [pscustomobject]@{ ComputerName = $comp DisplayName = $name DisplayVersion = $program.GetValue('DisplayVersion') Publisher = $program.GetValue('Publisher') InstallDate = $program.GetValue('InstallDate') UninstallString = $program.GetValue('UninstallString') Bits = $(if ($key -eq '\Wow6432Node') {'64'} else {'32'}) Path = $program.name } } } } } }
利用:
Get-InstalledApps -ComputerName $env:COMPUTERNAME