Uninstall a software "Webex" installed on one user
MoTaar
310
Reputation points
Hello,
I am trying to uninstall a webex software throuw a ps script because I want to uninstall it from all workstations. but the issue is that this script is not detecting the software because it's installed on one user. the script is run from the RMM as admin:
$SoftwareName ="webex"
#param ( [string]$SoftwareName)
if (-not $SoftwareName) {
Write-Host "Please provide the software name as a parameter. Example: .\UninstallSoftware.ps1 -SoftwareName 'Software Name'"
exit
}
# Registry paths to search for installed software
$uninstallKeys = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$found = $false
foreach ($key in $uninstallKeys) {
Write-Host "Working on Key: $key"
# Check if the registry key exists before attempting to query
if (Test-Path $key) {
# Get the uninstall information
$software = Get-ItemProperty $key | Where-Object { $_.DisplayName -like "*$SoftwareName*" }
if ($software) {
$found = $true
$uninstallString = $software.UninstallString
if ($uninstallString) {
Write-Host "Uninstalling $($software.DisplayName)..."
# Handle cases where the uninstall string is quoted or contains arguments
if ($uninstallString -match '^"([^"]+)"\s*(.*)') {
$exePath = $matches[1]
$arguments = $matches[2]
} else {
# Split the command manually
$parts = $uninstallString -split ' ', 2
$exePath = $parts[0]
$arguments = if ($parts.Count -gt 1) { $parts[1] } else { "" }
}
# Ensure the arguments include quiet and no restart options
Write-Host "arguments : $arguments"
# Check for silent/unattended mode arguments
if ($arguments -notmatch "/s|/S|/quiet|/silent") {
$arguments = " /quiet /norestart " + $arguments # Assuming /S or /silent for silent uninstallation
#$arguments = $arguments # With no /S or /silent for silent uninstallation
#$arguments = "/S /quiet /norestart " + $arguments # Assuming /S or /silent for silent uninstallation
}
# Check if the path exists
if (-Not (Test-Path $exePath)) {
Write-Host "Uninstaller not found: $exePath"
return
}
Write-Host "Executing: `"$exePath`" $arguments"
#Start-Process -FilePath $exePath -ArgumentList $arguments -Wait -NoNewWindow
Start-Process -FilePath $exePath -Wait -NoNewWindow
Write-Host "$($software.DisplayName) has been uninstalled."
} else {
Write-Host "Uninstall string not found for $($software.DisplayName)."
}
}
}else {
Write-Host "Registry path $key not found."
}
}
if (-not $found) {
Write-Host "No software found matching the name '$SoftwareName'."
}
Sign in to answer