選中此「嗨腳本專家」link。此鏈接描述如何通過註冊表查詢已安裝的應用程序。
從link:
的Win32_Product:黃金三鏢客 [好]的的Win32_Product WMI類代表,因爲他們安裝的產品> Windows安裝程序。
如果您選擇使用Get-WmiObject查詢Win32_Product類,您會發現>自己[Bad]正在等待您的查詢(或應用程序)返回[Ugly]>一致性檢查,因爲它已安裝嘗試驗證和修復安裝。 (有關更多信息,請參閱事件日誌消息指示> Windows安裝程序重新配置所有安裝的應用程序)。 ...
基於上面的鏈接,您可以通過查詢您安裝的產品:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
此外,您可以使用Test-Path
檢查請求的註冊表項存在。例如:
if (test-path HKLM:\Software\abc) { write-host "Found" } else { Write-Host "Not found" }
要檢查安裝的軟件在多個服務器上:
$servers = Get-Content C:\xyz\servers.txt
$results = @()
foreach ($server in $servers) {
$session = New-PSSession -ComputerName $server -Credential (Get-Credential)
$results += Invoke-Command -Session $session -ScriptBlock {
test-path HKLM:\Software\abc
}
}
$results.GetType() # Dump type
$results | gm # Dump properties
$results | Format-Table
希望有所幫助。
您發佈的代碼以何種方式執行您期望的操作? – arco444
請注意'Win32_Product'調用它驗證/修復每個安裝的msi。所以至少它是緩慢和過程密集型的。 – BenH
請提出任何其他替代方案.. – NJones