<# .SYNOPSIS Allows the uninstallation of Microsoft Office products via OffScrub. .EXAMPLE PS C:\> Invoke-OffScrub.ps1 -All # Removes all installed versions of Office. .EXAMPLE PS C:\> Invoke-OffScrub.ps1 -Office03 -Office10 -Office16 # Removes all detected instances of Office 2003, 2010, and 2016. .PARAMETER Office03 Uninstalls detected Office 2003 installs. .PARAMETER Office07 Uninstalls detected Office 2007 installs. .PARAMETER Office10 Uninstalls detected Office 2010 installs. .PARAMETER Office13 Uninstalls detected Office 2013 installs. .PARAMETER Office16 Uninstalls detected Office 2016 installs. .PARAMETER Officec2r Uninstalls detected Office Click-To-Run (Office 365) installs. .PARAMETER All Uninstalls all detected Office installs. #> [CmdletBinding()] param ( [Parameter(Mandatory=$false)][switch]$Office03, [Parameter(Mandatory=$false)][switch]$Office07, [Parameter(Mandatory=$false)][switch]$Office10, [Parameter(Mandatory=$false)][switch]$Office13, [Parameter(Mandatory=$false)][switch]$Office16, [Parameter(Mandatory=$false)][switch]$Officec2r, [Parameter(Mandatory=$false)][switch]$All ) ### Bootstrap ### if(-not $bootstrapLoaded) { [Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072) Invoke-Expression (New-Object System.Net.WebClient).DownloadString("https://file.provaltech.com/repo/script/Bootstrap.ps1") Set-Environment Update-PowerShell if($powershellUpgraded) { return } if($powershellOutdated) { return } } else { Write-Log -Text "Bootstrap already loaded." -Type INIT } ### Process ### if(-not $isElevated) { Write-Log -Message "This script requires elevation." -Type "ERROR" $identity return } $offScrub03 = "https://file.provaltech.com/repo/script/OffScrub03.vbs" $offScrub07 = "https://file.provaltech.com/repo/script/OffScrub07.vbs" $offScrub10 = "https://file.provaltech.com/repo/script/OffScrub10.vbs" $offScrub13 = "https://file.provaltech.com/repo/script/OffScrub13.vbs" $offScrub16 = "https://file.provaltech.com/repo/script/OffScrub16.vbs" $offScrubc2r = "https://file.provaltech.com/repo/script/OffScrubc2r.vbs" if($All) { Write-Log -Message "-All parameter specified. Attempting removal of all supported Office versions." $selectedVersions = @( $offScrub03, $offScrub07, $offScrub10, $offScrub13, $offScrub16, $offScrubc2r ) } else { $selectedVersions = @() if($Office03) {$selectedVersions += $offScrub03} if($Office07) {$selectedVersions += $offScrub07} if($Office10) {$selectedVersions += $offScrub10} if($Office13) {$selectedVersions += $offScrub13} if($Office16) {$selectedVersions += $offScrub16} if($Officec2r) {$selectedVersions += $offScrubc2r} } if(-not $selectedVersions) { Write-Log -Message "No Office versions selected." -Type "ERROR" return } Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows Script Host\Settings" -Name "Enabled" -Value 1 foreach ($version in $selectedVersions) { $lastIndex = $version.LastIndexOf('/') $fileName = $version.Substring($lastIndex + 1, $version.Length - $lastIndex - 1) $filePath = "$($workingPath)\$($fileName)" Write-Log -Text $filePath (New-Object System.Net.WebClient).DownloadFile($version, "$($filePath)") $output = & Cscript.exe $($filePath) ALL /Quiet /NoCancel /Force /OSE Write-Log -StringArray $output }