How to fix the issue "The file is corrupt and cannot be opened" when opening an Excel file (PowerShell)
Introduction
This PowerShell Script shows how to fix the issue "The file is corrupt and cannot be opened" when opening an Excel file.
Scenarios
Some consumers encounter an issue "The file is corrupt and cannot be opened" error on office Excel while opening .xls files. This script will try to fix that.
Script
Step1: Start the PowerShell Console with administrator. To type the one command< Script Path> with parameter at the Windows PowerShell Console.
For example, type C:\Script\FixExcelCorruptedError.ps1
The step is shown in the following figure.

When the script finishes running, you will see a brief message at the PowerShell Console.

Here are some code snippets for your references.
PowerShellEdit|Removepowershell$KeyPath = "HKCU:\Software\Microsoft\Office\" + "$Version" + "\Excel\Security" New-Item -Path $KeyPath -ItemType File -Name ProtectedView -Force -ErrorAction Stop | Out-Null Write-Verbose "Setting the value of registry." New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableInternetFilesInPV -Value 1 -Force -ErrorAction Stop | Out-Null New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableAttachmentsInPV -Value 1 -Force -ErrorAction Stop | Out-Null New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableUnsafeLocationsInPV -Value 1 -Force -ErrorAction Stop | Out-Null Write-Host "Successfully fixed Excel file corrupted error."$KeyPath = "HKCU:\Software\Microsoft\Office\" + "$Version" + "\Excel\Security" New-Item -Path $KeyPath -ItemType File -Name ProtectedView -Force -ErrorAction Stop | Out-Null Write-Verbose "Setting the value of registry." New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableInternetFilesInPV -Value 1 -Force -ErrorAction Stop | Out-Null New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableAttachmentsInPV -Value 1 -Force -ErrorAction Stop | Out-Null New-ItemProperty -Path "$KeyPath\ProtectedView" -Name DisableUnsafeLocationsInPV -Value 1 -Force -ErrorAction Stop | Out-Null Write-Host "Successfully fixed Excel file corrupted error."
Prerequisite
Windows PowerShell 2.0
Office Excel 2007 or higher version