Last active
February 25, 2021 15:39
-
-
Save tabs-not-spaces/24f6418d90fe4ca846405a9c6326adba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A few handy detection functions that I use every day |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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