Looping an uninstall per user
Hi All,
We have an app that we're attempting to convert to install, but one of my challenges is uninstalling the old method that installed into everyone's Appdata folder. It's one of the larger communication chat apps at the moment.
I know the command to uninstall it manually from the computer by using PDQ Inventory for an individual:
"C:\Users\%USERNAME%\AppData\Local\USERAPP\Update.exe" --uninstall -s
But I'm trying to figure out how to loop this and have never been much good on coding.
Basically:
Get a list of all user profiles on the computer
Run the command through all user profiles - but don't fail if the command was unsuccessful.
I'm sure that this has been done with other software prior to me - any ideas?
Comments
Mike,
Try this:
#Define your value of "USERAPP" here
$userApp = "USERAPP"
#Get a list of all user profiles on the system
$path = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*'
$profileList = Get-ItemProperty -Path $path | Select-Object -Property PSChildName, ProfileImagePath
#Run the command through all user profiles
foreach ($profile in $profileList) {
if (Test-Path $($profile.ProfileImagePath)\AppData\Local\$userApp\Update.exe) {
Invoke-Command "$($profile.ProfileImagePath)\AppData\Local\$userApp\Update.exe --uninstall -s"
}
}
#Close script with error code 0, indicating success
exit 0
I'm having this same issue with the same vendor's product it sounds like. Was this ever confirmed to work? Was this run as PowerShell?