Hello Johnny T ,
Thank you for reaching out on Microsoft Q&A.
I have updated the script to correctly reference the user profile paths using a parameter within the function, ensuring the correct user-specific paths are targeted during the uninstallation process. I have also removed Redundant function calls to improve the efficiency.
# Function to uninstall MicroSIP from a specific user profile
function UninstallMicroSIPFromUserProfile {
param (
[string]$userProfilePath
)
$MicroSIPUninstallPath = "$userProfilePath\AppData\Local\MicroSIP\Uninstall.exe"
Write-Output "Checking path: $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
& $MicroSIPUninstallPath /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."
}
}
# Check if the Users directory exists
if (!(Test-Path -Path "C:\Users")) {
Write-Output "Users directory does not exist on this drive. Current location: $($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
}
If you found this solution helpful, consider accepting it.