Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Remove read only attribute from folders, subfolders and subfolders

$
0
0

Hello Everyone,

I'm new to these forums and a total novice when it comes to PowerShell. Only started using a few commands with my new job and would like to learn more so joined your website. 

In the mean time, I have a favour to ask of you. I have a problem with OneDrive, upon some troubleshooting I found out it's not syncing the folders because they are set as read only. I used a command attrib C:\Temp\*.* -S -R /D /L but it only changes attributes on folders under Temp, not on subfolders under folders within Temp.

I looked on the net and came across this powershell script, that should change the attributes of all folders, including subfolders and their subfolders but wanted someone to check if it's correct before I go back to my client

$Path = "C:\Temp" 
$Files = Get-ChildItem $Path -Recurse
ForEach ($File in $Files
{
   Write-Host "File: " 
$File "IsReadOnly: " $File.IsReadOnly 
   if ($File.Attributes -ne "Directory" -and $File.Attributes -ne"Directory, Archive")
   {

      if ($File.IsReadOnly -eq $true )
      {
          try  

          {
               Set-ItemProperty -path $File.FullName -nameIsReadOnly -value $false 
               write-host "file:" $File.FullName "is now false read only"  -foregroundcolor "magenta"
          }
          catch 
[Exception] 
          { 
               Write-Host "Error at file " $Path "\" $File 
               Write-Host $_.Exception.Message
          }
      }
    } 
}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles