Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing permissions change ala chmod / attrib with Powershell

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?

like image 255
Paul Nathan Avatar asked Oct 30 '09 17:10

Paul Nathan


People also ask

How to change files and folders attributes using PowerShell?

How to change files and folders attributes using PowerShell? There are multiple files and folders attribute supported by the Windows Operating System. To check which attributes that files and folders support use DOS command attrib /? You can see the attributes listed like Read-Only, Archive, etc. You can set the attribute using PowerShell.

How to manage file and folder permissions in PowerShell?

The first PowerShell command used to manage file and folder permissions is Get-Acl; it lists all object permissions. A user must own both the target and source folders to copy permissions.

How do I define permissions for the Windows Registry with PowerShell?

When defining permissions for the Windows registry with PowerShell, you’ll need to create a System.Security.AccessControl.RegistryAccessRule object. This object allows you to define criteria like the principal (user, group, etc.) that this ACE applies to, level of access, and if you’re going to allow or deny that access.

What is the hierarchy for permissions in PowerShell?

The hierarchy for permissions is as follows: The first PowerShell command used to manage file and folder permissions is Get-Acl; it lists all object permissions. A user must own both the target and source folders to copy permissions.


1 Answers

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
like image 101
Keith Hill Avatar answered Oct 19 '22 07:10

Keith Hill