views:

518

answers:

1

I would like to do the equivalent of chmod -w+r-x foo or attrib +R foo in Windows Powershell. Putzing around, I notice a fairly gnarly Set-Acl function that looks significantly fancier than what I need.

How do I do attrib +R foo in Windows Powershell?

+3  A: 

The PowerShell Community Extensions comes with Set-Writable (aliased to swr) and Set-ReadOnly (aliased to sro). I use them both frequently. Removing execute privileges does require a change to the ACLs however using Get-Acl/Set-Acl is painful. I would use icacls.exe.

BTW if you don't want to mess with any 3rd party stuff, setting readonly to true/false is pretty easy:

Set-ItemProperty foo.txt IsReadOnly $true # or $false
Keith Hill
Well that's handy, I should check those out. Maybe I could retire a bunch of my hacked together scripts.
zdan
There's some pretty neat stuff in PSCX. Definitely worth checking out.
Keith Hill

related questions