Skip to content

Instantly share code, notes, and snippets.

@tabs-not-spaces
Last active February 25, 2021 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabs-not-spaces/24f6418d90fe4ca846405a9c6326adba to your computer and use it in GitHub Desktop.
Save tabs-not-spaces/24f6418d90fe4ca846405a9c6326adba to your computer and use it in GitHub Desktop.
A few handy detection functions that I use every day
function Test-AppInstallByFile {
param (
[string]$exePath,
[string]$appVersion
)
try {
if (Test-Path $exePath) {
if ($appVersion) {
$app = get-command $exePath
if ($appVersion -eq $app.Version) {
Write-Verbose "File found and version matches"
return $true
}
else {
Write-Verbose "File found but version doesnt match"
return $false
}
}
else {
Write-Verbose "File found not checking version"
return $true
}
}
else {
Write-Verbose "File not found"
return $false
}
}
catch {
Write-Verbose "An error occurred during testing"
return $false
}
}
function Find-AppByGuid {
param(
[string]$GUID
)
$GUIDKeys = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
if (Test-Path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\) {
$GUIDKeys += Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
}
if ($GUIDKeys | Where-Object {$_ -like "*$GUID"}) {
return $true
}
else {
return $false
}
}
Find-AppByGuid -Guid "c06d8ae5-69d3-49a2-84ce-f6e7af0ba9af"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment