Some deployment scripts need to check if certain required software is installed on a Windows Machine. You could check if the file is present at a certain location, but there is a better way: the uninstall database in the Windows Registry. PowerShell makes it really easy to query the registry using Get-ItemProperty. The path you want to query is HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*.

Example: is .Net Core 2.0 Runtime installed?

Let’s check:

$software = "Microsoft .NET Core Runtime - 2.0.0 (x64)";
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null

If(-Not $installed) {
	Write-Host "'$software' NOT is installed.";
} else {
	Write-Host "'$software' is installed."

The script is both readable and easy to understand.

Need something smaller?

If you really want to hurt yourself need something smaller. Check out this one-liner:

(gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | ? { $_.DisplayName -eq "Microsoft .NET Core Runtime - 2.0.0 (x64)" }) -ne $null

PowerShell for the win!