1

How to Remove ReadOnly Attribute on File Using PowerShell?

I have read that post, but when I tried

ls "C:\BAF\SILK\" -recurse -include *.* | Set-ItemProperty -name IsReadOnly -Value $false

it gives me error and I found out that it is because one of the subfolders have a dot in its name "e.g. Folder.bad". How can this be handled?

Community
  • 1
  • 1
FrozenLand
  • 259
  • 1
  • 4
  • 14

1 Answers1

2

You are getting a directory with your wildcard spec *.* i.e. Folder.bad. There isn't an IsReadOnly property on a Directory. Try this:

ls C:\BAF\SILK\*.* -r -file | ...

That requires PowerShell V3, if you are still on V2 (or V1) do this:

ls C:\BAF\SILK\*.* -r | Where {!$_.PSIsContainer} | ...
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Oh thank you very much! I kind of guessed that maybe IsReadOnly is a property to files and the reason why you can set that property for folders is that it actually sets that property for all the files in that folder instead of assigning that property to the folder. Thanks! I am using the latest powershell (i have win8 so they should automatically have v3 right?) – FrozenLand Oct 10 '13 at 18:21
  • @FrozenLand Yes, Windows 8 has PowerShell 3 by default. – Keith Hill Oct 10 '13 at 20:32