I’m trying to uninstall a software using this code
$path = "HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall{Product-cod-1}"
function Uninstall_SW {
Write-Host "Starting Uninstallation.."
if(Test-Path $path) {
$uninstallStr = (Get-ItemProperty -Path $path).UninstallString
if($uninstallStr) {
Write-Host "Uninstalling SW command: $uninstallStr"
Start-Process -FilePath "cmd.exe" ArgumentList "/c $uninstallStr /qn" -Wait -NoNewWindow
Write-Host "Uninstall Complete"
} else {
Write-Host "No uninstall str found"
} else {
Write-Host "Registry Path not found $path"
}
}
}
Unistall_SW
Now this work perfectly fine when I run locally on my laptop. But when this is deployed to Microsoft SCCM and on running this script in Software center, it fails to uninstall the software as it does not find the Registry Path and I have confirmed that the registry path is correct.
is there something I’m missing?
Note: Also tried with uninstall using get-package and uninstall package, but that does not work either