INSTRUCTIONS for engineers:

IMPORTANT DEPLOYMENT NOTE:

Deploy this as System and use the assignment method ‘Available for enrolled devices.’ Otherwise, if you assign it as ‘Required,’ users may lose their current work when the script runs automatically.

INSTRUCTIONS TO INCLUDE FOR USERS:

WARNING: This will close all Office apps. Please save your work first. Office apps will not be available during this process (which usually takes no more than 15 minutes).

  1. Please make sure to save all your work (otherwise, you will lose your work in Word, Excel, PowerPoint, Outlook, etc.) and click ‘Install’ on the Office Repair app.
  2. Then, leave the laptop for 15 minutes without opening any Office apps. (Otherwise, THE PROCESS MAY FAIL)
  3. Once the app shows as ‘Installed’ in your company portal, you can try opening Word, Excel, etc., and test iManage as well. This should resolve the issue.
  4. If the issue persists, please contact the Service Desk at [NUMBER].
  5. Log file will be created at C:\temp\office_repair_log.txt
Powershell script
# PowerShell Script to Repair Office via Click-to-Run (C2R) with Logging

# Define the log file path
$LogFilePath = "C:\temp\OfficeRepairLog.txt"

# Create log directory if it doesn't exist
if (-not (Test-Path "C:\temp")) {
    New-Item -ItemType Directory -Path "C:\temp"
}

# Function to write to log file
function Write-Log {
    param (
        [string]$Message
    )
    
    $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
    $logMessage = "$timestamp - $Message"
    Add-Content -Path $LogFilePath -Value $logMessage
}

# Log script start
Write-Log "Script started."

# Define the path for OfficeC2RClient
$OfficeC2RPath = "C:\Program Files\Common Files\Microsoft Shared\ClickToRun\OfficeC2RClient.exe"

# Check if OfficeC2RClient.exe exists
if (Test-Path $OfficeC2RPath) {
    Write-Log "OfficeC2RClient found. Proceeding with repair..."

    try {
        # Run the quick repair command (change to "quick" for a Quick Repair)
        Start-Process -FilePath $OfficeC2RPath -ArgumentList "repair quick" -Wait
        Write-Log "Quick repair initiated successfully."
    } catch {
        Write-Log "Error during repair: $_"
    }
} else {
    Write-Log "OfficeC2RClient not found. Office may not be installed or Click-to-Run is not used."
}

# Log script end
Write-Log "Script ended."

Visit my github repo https://github.com/dantcloud/intune-app-deployment/tree/main/MS-Office-Repair to download files.

Batch file to run quick repair
@echo off

:: Close all running Office applications
taskkill /f /im winword.exe
taskkill /f /im excel.exe
taskkill /f /im outlook.exe
taskkill /f /im powerpnt.exe
taskkill /f /im onenote.exe
taskkill /f /im mspub.exe

:: Wait a moment to ensure all Office apps are closed before starting the repair
timeout /t 5 /nobreak

:: Start Office repair and log output to a file
start /wait "" "C:\Program Files\Microsoft Office 15\ClientX64\OfficeClickToRun.exe" scenario=Repair platform=x64 culture=en-gb RepairType=QuickRepair DisplayLevel=False >> C:\temp\office_repair_log.txt 2>&1

:: Add completion message to log
echo Office repair completed successfully on %date% at %time% >> C:\temp\office_repair_log.txt
Batch file to delete the created log file
@echo off

:: Check if the log file exists and delete it
if exist C:\temp\office_repair_log.txt (
    del /f /q C:\temp\office_repair_log.txt
    echo Log file deleted successfully.
) else (
    echo Log file not found.
)

:: Exit the script
exit /b