Tuesday, 4 October 2016

Find and Change Read Only Files using Powershell

This script can be used to search for all files that are marked as "read only" on a windows file system. The script will search all files within the $targetdir variable (including all subfolders)

$targetdir = "D:\multimedia"

$readonlyfiles = get-childitem $targetdir -recurse | where {$_.isreadonly -eq $true}

If you wish to remove the read only property from any read only files that are found, we can adjust the script as per below;

$readonlyfiles = get-childitem $targetdir -recurse | foreach {if($_.isreadonly){$_.isreadonly = $false; write-host $_.fullname}}

The script will also display/echo back any files that it finds and changes from being read-only.

No comments:

Post a Comment