I had a need to remove the pre-installed Office 365 components. Thought I would share. Its a little messy and unrefined, but I tested it and its working. I’ll post update after I clean it up a little.
Evaluation
<#
.SYNOPSIS
Uninstall Application by Name - Evaluation Script
OS Support: Windows 7 and above
Required modules: NONE
.DESCRIPTION
This worklet is designed to grant an Admin the ability to uninstall an application with minimal knowledge of the bitness,
installer type, or uninstall command line. By placing an application name between the single quotes, the worklet will
scan the registry for the matching application. If the application is found, it will exit with an Exit code of '1' and
flag the device for remediation.
Usage:
$appName: The application name provided must match exactly as it is displayed in "Programs and Features" (Add or
Remove Programs) for Win7/8.1, and "Apps and Features" for Win10. Universal Windows Platform (UWP) applications are
not currently supported in this worklet.
Additional Notes:
Some software (such as M365 Apps) installs as a "suite" even though each component could have its own registry entry.
This type of installation is not supported with this worklet. For more information please see the software vendor's
support documentation.
.EXAMPLE
$appName = '7-Zip 19.00 (x64)'
.EXAMPLE
$appName = 'Microsoft Silverlight'
.NOTES
Author: eliles,rrodriguez
Date: February 24, 2021
#>
# Using scriptblock to relaunch in native environment for 64bit detection.
$scriptBlock = {
######## Make changes within the block ########
# Add Application name exactly as it appears in Add/Remove Programs, Programs and Features, or Apps and Features between single quotes.
$appName = 'Microsoft 365*'
###############################################
# Define registry location for uninstall keys
$uninstReg = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
# Get all entries that match our criteria. DisplayName matches $appName (using -like to support special characters)
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {($_.DisplayName -like $appName)})
# If any matches were found, $installed will return a "1" and pass it to $exitCode flagging the device for remediation.
if ($installed)
{
return 1
}
else
{
return 0
}
}
# Execution of $scriptBlock
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock
# Exit with value provided by $installed
Exit $exitCode
Remediation Code
$scriptBlock = {
$appName = '*OfficeClickToRun.exe*'
###############################################
# Define registry location for uninstall keys
$uninstReg = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
# Get all entries that match our criteria. DisplayName matches $appName (using -like to support special characters)
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {($_.UninstallString -like $appName)})
foreach ($crap in $installed) {
$arg = $crap.uninstallstring.substring(81).tostring() + " DisplayLevel=False"
Start-Process "C:\Program Files\Common Files\Microsoft Shared\ClickToRun\OfficeClickToRun.exe" -ArgumentList "$arg" -wait
}
}
# Execution of $scriptBlock
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock
# Exit with value provided by $installed
Exit $exitCode