Skip Navigation LinksHome > View Post
How to remove a file attribute in PowerShell

Or, in this case, how to make a file not readonly in powershell. It took me a while to get this working and this is my best effort. In fact, this particular example recurses a whole folder and makes all files not readonly

$readonly = [System.IO.FileAttributes]::ReadOnly
get-childitem . -recurse | foreach { if ($_.Attributes -band $readonly -eq $readonly) { $_.Attributes -= $readonly.value__ } }

I did try to set the IsReadOnly property but Powershell throws a wobbly at that. If anybody knows a neater way of doing this I'd love to know.

Josh Post By Josh Twist
4:37 AM
27 Jun 2008

Comments:

Posted by Adrian Bateman @ 27 Jun 2008 7:14 AM
Why Powershell? I mean, I like Powershell and all, but why wouldn't you just use attrib?

Posted by Josh @ 28 Jun 2008 10:41 AM
Why not use attrib?

If you don't know about it :)

That's much neater:

get-childitem <folder> -recurse | attrib -R

or

attrib -R /S

to do it for the whole current folder

Posted by Adrian Bateman @ 30 Jun 2008 2:14 PM
Ah, that'd do it. :o)

Two weeks ago I could have given you my DOS 3.3 manuals to gen up on this stuff. Unfortunately I no longer own them. Oh well!

Post a comment:

Name  

E-mail (never shared)

URL

Comments  

Captcha ImageRefresh Image
What's this?
Enter code above