2017-03-14 187 views
0

我需要檢查是否安裝了軟件列表。我不想列出計算機上安裝的所有軟件,而只需要列出特定軟件的列表,以及它是否已安裝。如果該軟件未安裝,則需要安裝。如何查找給定軟件是否已安裝,以及是否未安裝如何使用PowerShell安裝它?

這就是我所做的,誰能告訴我如何進行?

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
    Export-Csv C:"path" 

此代碼顯示計算機上安裝的軟件的完整列表。我如何定製它只顯示我想要的軟件,如果我發現它沒有安裝,我該如何安裝軟件?

+0

可能的重複[如何使用PowerShell卸載應用程序?](http://stackoverflow.com/questions/113542/how-can-i-uninstall-an-application-using-powershell) –

+0

它總是首先尋找一個存在的問題的好主意http://stackoverflow.com/questions/113542/how-can-i-uninstall-an-application-using-powershell –

+0

那麼,該腳本將是靜態的不是嗎? –

回答

0

您可以編寫一個參數化腳本,允許您爲特定條目篩選註冊表值。當然你的腳本也需要知道爲哪個過濾器字符串調用哪個安裝程序。

[CmdletBinding()] 
Param(
    [Parameter(Mandatory=$true)] 
    [string]$Filter 
) 

$key = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' 

$installers = @{ 
    'foo' = '\\server\share\some_installer.exe' 
    'bar' = '\\server\share\other_installer.msi' 
} 

$software = Get-ItemProperty "$key\*" | 
      Where-Object { $_.DisplayName -like "*$Filter*" } 

if (-not $software) { 
    $installers.Keys | Where-Object { 
    $_ -like "*$Filter*" 
    } | ForEach-Object { 
    & $installers[$_] 
    } 
} 

需要注意的是,除非你只需要檢查的32位程序需要處理64位的卸載鍵,以及(也許還有用戶密鑰)。

相關問題