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.

Tags: Other

Josh Post By Josh Twist
04:37
27 Jun 2008

» Next Post: Creating AD user accounts in PowerShell
« Previous Post: What's next for Ukadc.Diagnostics?

Comments:

Posted by Adrian Bateman @ 27 Jun 2008 07:14
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
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 14:14
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!

Posted by Sam @ 20 Mar 2009 12:09
Clear-ItemProperty C:\Temp\webproduction\elcabop.vsmdi -Name attributes -force

Posted by Sam @ 20 Mar 2009 12:11
Clear-ItemProperty C:\Temp\webproduction\elcabop.vsmdi -Name attributes -force

Post a comment:

Name  

E-mail (never shared)

URL

Comments  

Captcha ImageRefresh Image
What's this?
Enter code above