$chocoPackage = choco list $myPackageName --exact | Where-Object {$_.StartsWith($myPackageName)} if ($chocoPackage -ne $null) { }
but it's true even when it's not installed.Chocolatey CLI will take care of the package. What you're asking about is the software.
The chocolateyBeforeModidy.ps1
is run during upgrade or uninstall of the package. It's generally used to check for running services, processes, etc.
Don't using choco
command inside package scripts. It may lead to issues.
The best way to check if software is already installed is to check whatever it does to the system to 'register' it's installed. So this could be registry changes, file system changes or something else.
I do this with Keepass plugin packages that I maintain. As Keepass could be installed in many places, and in different ways, I check them all.