Remove app from user context and deploy this script via Intune
I am trying to uninstall a application called MicroSIP via Microsoft Intune on all of our Windows machines but the script is says "not installed" every time I run it. I have tied multiple scripts but no luck. I did find my issue. So here it is. Every time the script rans it looks under C:\Users for the name of the MACHINE instead of the USER when expanding %USERNAME%. I have not idea what I am doing wrong
Here is my script
Function to uninstall MicroSIP from a specific user profile
function UninstallMicroSIPFromUserProfile($userProfilePath) {
$MicroSIPUninstallPath = "$userProfilePath\AppData\Local\MicroSIP\Uninstall.exe"
Write-Output $MicroSIPUninstallPath
if (Test-Path -path $MicroSIPUninstallPath) {
Write-Output "Uninstalling MicroSIP from $userProfilePath..."
# Stop any running instances of MicroSIP to avoid conflicts
Stop-Process -Name MicroSIP -Force -ErrorAction SilentlyContinue
# Uninstall MicroSIP
cmd.exe /c ""%SYSTEMDRIVE%\Users\%USERNAME%\Appdata\Local\MicroSIP\Uninstall.exe" /S"
# Check if the uninstallation was successful
if (Test-Path -path $MicroSIPUninstallPath) {
Write-Output "Failed to uninstall MicroSIP from $userProfilePath. Please try again or manually remove it."
} else {
Write-Output "MicroSIP successfully uninstalled from $userProfilePath."
}
} else {
Write-Output "MicroSIP is not installed in $userProfilePath."
}
}
if (!(Test-Path -path "C:\Users")) {
Write-Output "Users directory does not exist on this drive. Current location: "
Write-Output $MyInvocation.MyCommand.Path
Exit
}
Get the list of user profiles on the machine
$userProfiles = Get-ChildItem "C:\Users" -Directory
Loop through each user profile and uninstall MicroSIP
foreach ($profile in $userProfiles) {
UninstallMicroSIPFromUserProfile $profile.FullName
UninstallMicroSIPFromUserProfile $profile.FullName
UninstallMicroSIPFromUserProfile $profile.FullName
UninstallMicroSIPFromUserProfile $profile.FullName
}