I just wanted to have some advice on those remediation scripts; what do you think?
The idea is to detect every 7-Zip installed on the computer and search for those not up to date and uninstall them. Got some Struggle with placing correctly the exits code used by Intune.
Detection Script:
$64bits = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -match "7-Zip"
$32bits = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -match "7-Zip"
if (!($64bits) -and !($32bits)){
Write-Host "7-Zip isnt detected at all"
exit 0
}
if ($64bits){
foreach ($soft in $64bits){
Write-Host "7-Zip(x64) ver:" $soft.DisplayVersion "detected"
if ($soft.DisplayVersion -lt "23.01"){
exit 1
}
}
}
else {
Write-Host "7-Zip(x64) isnt detected"
}
if ($32bits){
foreach ($soft in $32bits){
Write-Host "7-Zip(x86) ver:" $soft.DisplayVersion "detected"
if ($soft.DisplayVersion -lt "23.01"){
exit 1
}
}
}
else {
Write-Host "7-Zip(x86) isnt detected"
}
Remediation Script:
$64bits = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -match "7-Zip"
if ($64bits){
foreach ($soft in $64bits){
if ($soft.DisplayVersion -lt "23.01"){
Write-host "Uninstall" $soft.DisplayName $soft.DisplayVersion
Start-Process $soft.UninstallString -ArgumentList "/S"
}
}
}
$32bits = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object DisplayName -match "7-Zip"
if ($32bits){
foreach ($soft in $32bits){
if ($soft.DisplayVersion -lt "23.01" -or $soft.DisplayVersion -eq $null){
Write-Host "7-Zip(x86) ver:" $soft.DisplayVersion "detected"
Start-Process $soft.UninstallString -ArgumentList "/S"
Write-host "Uninstall" $soft.DisplayName $soft.DisplayVersion
}
}
}
exit 0