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 $_ }
2 Likes

I’m working on a similar thing, I have a customer who needs all versions of office except for apps for business in en-us language to be removed because it is conflicting with some third party apps they use and brand new (dell) machines are coming with various versions of office pre installed in various languages:

Aplicaciones de Microsoft 365 para negocios - es-es
Microsoft 365 - en-us
Microsoft 365 - es-es
Microsoft 365 - fr-fr
Microsoft 365 Apps for business - fr-fr
Microsoft 365 Apps para Pequenos e Médios negócios - pt-br

I found this suite of scripts at Office-IT-Pro-Deployment-Scripts/Office-ProPlus-Deployment/Remove-PreviousOfficeInstalls at master · OfficeDev/Office-IT-Pro-Deployment-Scripts · GitHub but they are packaged in vbs or a powershell wrapper so I’m looking at having to write get/set cases and either package them in a zip to transfer as a software package or modify the script to download the vbs files it needs.

I would really like to be able to tell immybot to remove specific language packs, or have an option to remove all but the selected language pack. It doesn’t look like that functionality is included and as Andre said they don’t seem to uninstall consistently. I suspect that is because microsoft has so many variations on the office installs.

1 Like