#Requires -Version 5.1 <# JbTecWiz Support Centre -- generated fix script Fault : A document always opens read-only Fix : Clear the read-only attribute and the recommendation flag Source: https://jbtecwiz.com/support/win-office-read-only Run as : PowerShell as the affected user Expect : 10 minutes Risk : low Reversible : yes WHEN THIS IS THE RIGHT FIX The file follows the problem wherever it is copied. Start here. HOW TO UNDO IT Set IsReadOnly back to $true, or re-tick Read-only recommended, if the protection was deliberate. 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 SCRIPT WILL NOT RUN UNTIL YOU EDIT IT - # The commands below contain values only you can supply. Search the # script for each one, replace it, then delete this block. $script:MustEdit = @( 'C:\path\to\file.docx' # a placeholder file path 'C:\path\to\folder' # a placeholder file path ) if ($script:MustEdit.Count) { Write-Host "" Write-Host ' This script needs editing before it can run.' -ForegroundColor Yellow Write-Host ' Replace each of these with a real value:' -ForegroundColor Yellow $script:MustEdit | ForEach-Object { Write-Host (" " + $_) -ForegroundColor Yellow } Write-Host "" Write-Host ' Then delete the $script:MustEdit block near the top.' Write-Host "" exit 2 } 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 4" 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 ' A document always opens read-only' -ForegroundColor White Write-Host ' Clear the read-only attribute and the recommendation flag' -ForegroundColor Cyan Write-Host '' Write-Host ' Risk: low Reversible 10 minutes' 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 'Check the file system attribute.' -Why 'Files restored from a backup, extracted from some zip tools, or copied from a CD or a locked-down share very often arrive with this set, and nothing in Office says so beyond the words Read-Only.' -Command { Get-ItemProperty 'C:\path\to\file.docx' | Select-Object Name, IsReadOnly, Attributes } Invoke-Step -Number 2 -Do 'Clear it.' -Command { Set-ItemProperty 'C:\path\to\file.docx' -Name IsReadOnly -Value $false } Invoke-Step -Number 3 -Do 'For a whole folder that came from a backup.' -Command { Get-ChildItem 'C:\path\to\folder' -Recurse -File | Where-Object IsReadOnly | Set-ItemProperty -Name IsReadOnly -Value $false } Invoke-Step -Number 4 -Do 'If the attribute was already clear, check the read-only-recommended flag, which is saved inside the document. Open it, then File -> Save As -> Tools -> General Options, and clear "Read-only recommended".' -Why 'This flag is stored in the file, so it survives copying and appears on every machine. It is a recommendation rather than a lock, which is why Edit Anyway works and why it is so often left in place for years.' -Manual Write-Rule " Confirm it worked" Show-Prose 'The file opens for editing with no read-only notice and saves in place.' '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-read-only' 'Yellow' } else { Write-Host ' Finished.' -ForegroundColor Green } Write-Host '' Show-Prose 'To undo: Set IsReadOnly back to $true, or re-tick Read-only recommended, if the protection was deliberate.' 'DarkGray' Write-Rule