Make a File Read-Only (and Back) with PowerShell

Toggle the IsReadOnly attribute on any file to lock it from edits or unlock it again.

WindowsFilesattributespowershellLow risk
Run `Set-ItemProperty -Path "C:\Docs\report.xlsx" -Name IsReadOnly -Value $true` to make a file read-only; use $false to unlock.

01Command

Command
$ Set-ItemProperty -Path "C:\Docs\report.xlsx" -Name IsReadOnly -Value $true  ::  $false to undo

02What it does

Every file in NTFS carries an IsReadOnly flag; when it's true, apps that honor the attribute refuse to save over the file. Set-ItemProperty flips it directly, and Get-ItemProperty shows the current state. This is ideal for protecting template or invoice files you keep overwriting by accident.

03Risk

RiskLow risk
RequirementsWindows PowerShell; write access to the file.
!Warning: Read-only is a soft lock — a program can still delete the file or a user can clear the attribute.

04Undo

Undo
$ Set-ItemProperty -Path "C:\Docs\report.xlsx" -Name IsReadOnly -Value $false

05Sources

Last verified: 2026-09-19 · Category: Files & Folders

06Related solutions