PowerShell: How to Remove ReadOnly Attribute on File


You can use the following syntax in PowerShell to check if a file is read-only:

$my_file.IsReadOnly

This particular example will return either True or False to indicate if the file saved in the variable named $my_file is read-only or not.

If the file is read-only, then you can use the following syntax to remove this ReadOnly attribute:

$my_file.IsReadOnly = $false

This will remove the ReadOnly attribute from the file.

The following example shows how to use this syntax in practice.

Example: Use PowerShell to Remove ReadOnly Attribute on File

Suppose that we have a file named athletes.txt in our current directory.

We can use the following syntax to store this file in a variable named $my_file and then check whether or not the file is read-only:

$my_file = Get-Item 'athletes.txt'
$my_file.IsReadOnly

The following screenshot shows how to use this syntax in practice:

PowerShell check if file is read-only

We can see that this returns True, which indicates that the file is currently set to read-only.

To remove this read-only attribute from the file, we can use the following syntax:

$my_file.IsReadOnly = $false

The following screenshot shows how to use this syntax in practice:

PowerShell remove ReadOnly attribute from file

When we type $my_file.IsReadOnly once again, we can see that it returns False this time.

This tells us that we have successfully removed the read-only attribute on the file.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Delete All Files with Specific Extension
PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to Add Date to File Name

Leave a Reply