M365 Office, OneNote, Teams - Home/Retail/Personal - Uninstall Script

I commonly have issue translating script that successfully completes he task via ISE as Admin to a system script. Cannot attempt to uninstall using the latest version’s uninstall script because it is not present.
None of the software removal processes were successful.

immy.bot is no longer removing these things properly. i get the same error for Immy’s that i did above.

M365 Office, OneNote, Teams - Home/Retail/Personal - Uninstall Script
# Uninstall Microsoft Teams (personal)
Write-Output "Checking for Microsoft Teams (personal)..."
$teamsPackages = Get-AppxPackage | Where-Object { $_.PackageFullName -like "*MicrosoftTeams*" } | Select-Object Name, PackageFullName

if ($teamsPackages) {
    Write-Output "Found Microsoft Teams (personal):"
    $teamsPackages | ForEach-Object { Write-Output $_.PackageFullName }
    Write-Output "Uninstalling Microsoft Teams (personal)..."
    $teamsPackages | ForEach-Object { Remove-AppxPackage -Package $_.PackageFullName }
    Start-Sleep -Seconds 10
    $teamsPresence = Get-AppxPackage | Where-Object { $_.PackageFullName -like "*MicrosoftTeams*" }

    if ($teamsPresence) {
        Write-Output "Microsoft Teams (personal) is still present:"
        $teamsPresence | Select-Object Name, PackageFullName | ForEach-Object { Write-Output $_.PackageFullName }
    } else {
        Write-Output "Microsoft Teams (personal) has been successfully uninstalled."
    }
} else {
    Write-Output "Microsoft Teams (personal) is not installed."
}

# Define the uninstall commands
$uninstallCommands = @(
    'OneNoteFreeRetail.16_en-us_x-none culture=en-us',
    'OneNoteFreeRetail.16_en-gb_x-none culture=en-gb',
    'OneNoteFreeRetail.16_fr-fr_x-none culture=fr-fr',
    'OneNoteFreeRetail.16_de-de_x-none culture=de-de',
    'OneNoteFreeRetail.16_es-es_x-none culture=es-es',
    'OneNoteFreeRetail.16_it-it_x-none culture=it-it',
    'OneNoteFreeRetail.16_ja-jp_x-none culture=ja-jp',
    'OneNoteFreeRetail.16_zh-cn_x-none culture=zh-cn',
    'OneNoteFreeRetail.16_pt-br_x-none culture=pt-br',
    'O365HomePremRetail.16_en-us_x-none culture=en-us',
    'O365HomePremRetail.16_en-gb_x-none culture=en-gb',
    'O365HomePremRetail.16_fr-fr_x-none culture=fr-fr',
    'O365HomePremRetail.16_de-de_x-none culture=de-de',
    'O365HomePremRetail.16_es-es_x-none culture=es-es',
    'O365HomePremRetail.16_it-it_x-none culture=it-it',
    'O365HomePremRetail.16_ja-jp_x-none culture=ja-jp',
    'O365HomePremRetail.16_zh-cn_x-none culture=zh-cn',
    'O365HomePremRetail.16_pt-br_x-none culture=pt-br'
)

# Initialize a report array
$report = @()

# Loop through each uninstall command
foreach ($command in $uninstallCommands) {
    Write-Output "Starting uninstallation for: ${command}"
    try {
        # Uninstall command
        $uninstallString = "C:\Program Files\Common Files\Microsoft Shared\ClickToRun\OfficeClickToRun.exe"
        $arguments = "scenario=install scenariosubtype=ARP sourcetype=None productstoremove=${command} version.16=16.0 displaylevel=false forceappshutdown=true"
        
        # Log the command being run
        Write-Output "Executing command: $uninstallString $arguments"
        
        # Start the process and wait for it to exit
        $process = Start-Process -FilePath $uninstallString -ArgumentList $arguments -Wait -NoNewWindow -PassThru
        Write-Output "Process started. Waiting for it to complete..."
        
        # Confirm uninstall
        if ($process.ExitCode -eq 0) {
            $report += "Successfully uninstalled ${command}"
            Write-Output "Successfully uninstalled ${command}"
        } else {
            $report += "Failed to uninstall ${command} with exit code $($process.ExitCode)"
            Write-Output "Failed to uninstall ${command} with exit code $($process.ExitCode)"
        }
    } catch {
        # Handle errors
        $report += "Error uninstalling ${command}: $_"
        Write-Output "Error uninstalling ${command}: $_"
    }
}

# Output the report to the console
Write-Output "Uninstallation process completed. Summary report:"
$report | ForEach-Object { Write-Output $_ }
1 Like