Hi, I would like to check if some packages are already installed, if they are not, i want to install them.
I tried a many things but the "winget list --id" return an object, and i'm not able to figure it out how to manage it.
[int]$isInstalled = -1
Function testPackage ($packageName){
[string]$test = ""
try {
$test = winget list --id $packageName
} catch {
$test = ""
}
if ($test = "") {
$isInstalled = 1
}
else {
$isInstalled = 0
}
return $isInstalled
}
foreach ($utility in $toInstall) { #$toInstall is a string array with all the id of the packages that i need
if (testPackage($utility) -eq 1) {
write-host "installing $utility..."
winget install -e --id $utility
}
else {
Write-Host "$utility already installed";
}
}
can anybody help me?
thank you