Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Powershell: Add or remove the ‘Read Only’ attribute from files

Use Microsoft PowerShell to add or remove the ‘read only’ attribute from large batches of files in a directory.

Making all files ‘Read Only’

The process of making all files in a directory ‘read only’ is quite easy using Microsoft PowerShell. The simplest approach is:

$source="c:\path\to\files\*" #path to files
Set-ItemProperty -Path $source -Name IsReadOnly -Value $true

The file attribute changes to ‘read only’ because IsReadOnly is set to “true”.

Making files of type ‘Read Only’

If the aim is to make only certain file types ‘read only’, that can be achieved my specifying the file types in the code. In this example, only .jpg and .png files will become ‘read only’:

$source="c:\path\to\files\*" #path to files
Set-ItemProperty -Path $source -include @("*.png", "*.jpg") -Name IsReadOnly -Value $true

Removing the ‘Read Only’ attribute from files

To remove the ‘read only’ attribute from files, the above code can be altered so that IsReadOnly is set to “false”. The following code would remove the ‘read only’ attribute from .jpg and .png files:

$source="c:\path\to\files\*" #path to files
Set-ItemProperty -Path $source -include @("*.png", "*.jpg") -Name IsReadOnly -Value $true


The following code will allow sub-directories to be recursed:

$source="c:\path\to\files\*" #path to files
Get-Childitem -Recurse -Path $source -include @("*.png", "*.jpg") | Set-ItemProperty -Name IsReadOnly -Value $true


One response to “Powershell: Add or remove the ‘Read Only’ attribute from files”

On 11 August 2017, matt wrote: Hyperlink chain icon

should the $value be set to false when trying to remove the read only attribute? above you have it set to true in your example of removing it.


Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.