2
試圖通過使用DisplayName值的匹配進行搜索來掃描某些軟件的註冊表的卸載字符串。我可以通過一個軟件來實現它,但是我有麻煩找出如何使它與軟件列表一起工作。例如,我將Java,Silverlight,Shockwave,Adobe Reader和Adobe Font Pack設置爲變量,但無法弄清楚如何通過foreach
命令循環它們。循環內循環?
$PATHS = @("HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
# Java 8 Update 102 | 8.0.1020.14
$Javax86 = "Java 8"
# Microsoft Silverlight | 5.1.50901.0
$MSsilverlight = "Microsoft Silverlight"
# Adobe Shockwave Player 12.2 | 12.2.5.195
$AdobeShockwave = "Adobe Shockwave Player"
# Extended Asian Language font pack for Adobe Acrobat Reader DC | 15.007.20033
$AdobeReaderFont = "font pack for Adobe Acrobat Reader"
# Adobe Acrobat Reader DC MUI | 15.020.20042
$AdobeReader = "Adobe Acrobat Reader DC MUI"
$SOFTWARE = ""
#@($Javax86,$MSsilverlight,$AdobeShockwave,$AdobeReaderFont,$AdobeReader)
foreach ($path in $PATHS) {
$installed = Get-ChildItem -Path $path |
foreach { Get-ItemProperty $_.PSPath } |
Where-Object { $_.DisplayName -match "$MSsilverlight" } |
Select-Object -Property DisplayName,DisplayVersion
foreach ($app in $installed) {
$DisplayName = "$($app.DisplayName)"
$DisplayVersion = "$($app.DisplayVersion)"
}
if ($app.DisplayName) {
$InstalledYes = "$DisplayName ($DisplayVersion) is installed"
} elseif ($app.DisplayName -eq $NULL) {
$InstalledNo = "$MSsilverlight is not Installed"
#Write-Host "$SOFTWARE is not installed"
}
}
Write-Host "$InstalledYes"
Write-Host "$InstalledNo"
你不需要管道後面的刻度線。請不要使用刻度線(永遠)繼續行。 –