#Requires -Version 5.1 <# JbTecWiz Support Centre -- generated fix script Fault : Office will not install or repair -- 30015, 30088, 30183, 30029-4, 1058-13 Fix : Remove the remains of the previous install properly Source: https://jbtecwiz.com/support/win-office-install-fail Run as : PowerShell as administrator, with the machine free for a restart Expect : 1 hour Risk : medium Reversible : NO -- read the undo note below before running WHEN THIS IS THE RIGHT FIX A repair fails, or a previous version was uninstalled and the new one will not go on. Appwiz uninstall routinely leaves registration behind that blocks the next install. HOW TO UNDO IT There is no rollback -- this deliberately removes the installation. Documents are not touched, but the install itself has to be redone. Confirm the licence and the sign-in details are to hand before starting. This script walks the fix one step at a time and asks before each one. Steps with no command are things you do yourself -- it prints those and waits. Run with -DryRun to print without executing. #> [CmdletBinding()] param( # Print every step and command without running anything. [switch]$DryRun, # Do not ask before each step. Read the script first if you use this. [switch]$Unattended ) $ErrorActionPreference = 'Stop' $script:Failed = 0 # This fix is documented as needing an elevated session. $id = [Security.Principal.WindowsIdentity]::GetCurrent() if (-not (New-Object Security.Principal.WindowsPrincipal $id).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host '' Write-Host ' This fix needs an elevated PowerShell.' -ForegroundColor Yellow Write-Host ' Close this window, right-click PowerShell, Run as administrator,' Write-Host ' and run the script again.' Write-Host '' exit 3 } function Write-Rule { param([string]$Text) Write-Host '' Write-Host ('-' * 70) -ForegroundColor DarkGray if ($Text) { Write-Host $Text -ForegroundColor Cyan } } function Show-Prose { param([string]$Text, [string]$Colour = "Gray") if (-not $Text) { return } $words = $Text -split "\s+"; $line = " " foreach ($w in $words) { if (($line.Length + $w.Length) -gt 74) { Write-Host $line -ForegroundColor $Colour; $line = " " } $line += "$w " } if ($line.Trim()) { Write-Host $line -ForegroundColor $Colour } } function Invoke-Step { param( [int]$Number, [string]$Do, [string]$Why, [scriptblock]$Command, [switch]$Manual, [string]$Shell = "powershell" ) Write-Rule " Step $Number of 5" Show-Prose $Do "White" if ($Why) { Write-Host ""; Show-Prose $Why "DarkGray" } if ($Manual) { Write-Host '' Write-Host ' -> Do this yourself, then press Enter to carry on.' -ForegroundColor Yellow if (-not $Unattended -and -not $DryRun) { [void](Read-Host) } return } Write-Host '' foreach ($l in ($Command.ToString().Trim() -split "`n")) { Write-Host (" " + $l.Trim()) -ForegroundColor Green } Write-Host '' if ($DryRun) { Write-Host " (dry run -- not executed)" -ForegroundColor DarkGray; return } if (-not $Unattended) { $a = Read-Host " Run this step? [Y]es / [S]kip / [Q]uit" if ($a -match "^[Qq]") { Write-Host " Stopped at your request."; exit 0 } if ($a -match "^[Ss]") { Write-Host " Skipped." -ForegroundColor DarkGray; return } } try { & $Command } catch { $script:Failed++ Write-Host (" Step $Number failed: " + $_.Exception.Message) -ForegroundColor Red Show-Prose "The rest of the fix may depend on this. Read the write-up before carrying on." "Red" if (-not $Unattended) { $c = Read-Host " Carry on anyway? [y/N]" if ($c -notmatch "^[Yy]") { exit 1 } } } } Write-Rule Write-Host ' Office will not install or repair -- 30015, 30088, 30183, 30029-4, 1058-13' -ForegroundColor White Write-Host ' Remove the remains of the previous install properly' -ForegroundColor Cyan Write-Host '' Write-Host ' Risk: medium NOT REVERSIBLE 1 hour' -ForegroundColor Yellow Write-Host '' Show-Prose 'Undo: There is no rollback -- this deliberately removes the installation. Documents are not touched, but the install itself has to be redone. Confirm the licence and the sign-in details are to hand before starting.' 'Yellow' Write-Rule if (-not $Unattended -and -not $DryRun) { $go = Read-Host ' Ready? [y/N]' if ($go -notmatch "^[Yy]") { Write-Host " Nothing was changed."; exit 0 } } Invoke-Step -Number 1 -Do 'Record what is currently registered, so you know what to put back.' -Why 'ProductReleaseIds is the list of products the licence covers. Reinstalling without it gets you a different edition than the one that was there, which is the usual reason activation then fails as well.' -Command { Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration' | Format-List ProductReleaseIds, Platform, UpdateChannel, ClientCulture } Invoke-Step -Number 2 -Do 'Download and run the Microsoft Support and Recovery Assistant''s Office uninstall tool. It is the only removal that clears the Click-to-Run registration, the scheduled tasks, the shell extensions and the licence tokens together.' -Command { Start-Process 'https://aka.ms/SaRA-officeUninstallFromPC' } Invoke-Step -Number 3 -Do 'Let it restart the machine when it asks. Do not skip this -- the removal is not complete until the pending file operations have run.' -Manual Invoke-Step -Number 4 -Do 'Confirm nothing is left registered before reinstalling.' -Why 'This should now be False. If it is still True the removal did not finish, and reinstalling on top will reproduce the original error.' -Command { Test-Path 'HKLM:\SOFTWARE\Microsoft\Office\ClickToRun' } Invoke-Step -Number 5 -Do 'Reinstall from the portal, choosing the same architecture and the same products you recorded in the first step.' -Manual Write-Rule " Confirm it worked" Show-Prose 'Office installs to completion, opens, and shows the correct account under File -> Account.' 'White' Write-Rule if ($script:Failed -gt 0) { Write-Host (" Finished with " + $script:Failed + " failed step(s).") -ForegroundColor Yellow Show-Prose 'Read the full write-up at https://jbtecwiz.com/support/win-office-install-fail' 'Yellow' } else { Write-Host ' Finished.' -ForegroundColor Green } Write-Host '' Show-Prose 'To undo: There is no rollback -- this deliberately removes the installation. Documents are not touched, but the install itself has to be redone. Confirm the licence and the sign-in details are to hand before starting.' 'DarkGray' Write-Rule