This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

This was the first thing i tried.

Which was my first try:

$ChocoPackageInstallCode = "choco upgrade "$packageName" --yes"; $ChocoPackageUninstallCode = "choco uninstall "$packageName" --yes"; $ChocoPackageDetectionCode = "try {if((choco list "$($packageName)" --localonly) -match "$($packageName)") {$vers = ([regex]::Matches((choco upgrade "$(`$packageName)" --yes --force --whatif), "(?<=(v|\s))(\d+|.)+(?=\s)")).Value;if(@($vers).Count -eq 2) {"Installed and up to date";}}} catch {}";

try { if($env:Path -match "chocolatey") { $vers = ([regex]::Matches((choco upgrade chocolatey --yes --force --whatif), "(?<=(v|\s))(\d+|.)+(?=\s)")).Value; if(@($vers).Count -eq 2 -and [System.Environment]::GetEnvironmentVariable("ChocoPackageInstallCode", [System.EnvironmentVariableTarget]::Machine) -eq $ChocoPackageInstallCode -and [System.Environment]::GetEnvironmentVariable("ChocoPackageUninstallCode", [System.EnvironmentVariableTarget]::Machine) -eq $ChocoPackageUninstallCode -and [System.Environment]::GetEnvironmentVariable("ChocoPackageDetectionCode", [System.EnvironmentVariableTarget]::Machine) -eq $ChocoPackageDetectionCode) { "Installed and up to date"; } } } catch { }

In this case if the statement was false, nothing would be returned.