Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning file access rights to IIS_IUSRS using PowerShell

I'm trying to add access rights for the user group IIS_IUSRS to a folder using PowerShell.

Currently I have

$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\IIS_IUSRS", "FullControl", "Allow")
$acl = Get-ACL "C:\tmp"
$acl.AddAccessRule($accessRule)
Set-ACL -Path "C:\tmp" -ACLObject $acl

When run, this adds IIS_IUSRS to the list of users but there are no privileges assigned.

enter image description here

What have I missed?

like image 993
awj Avatar asked Jul 20 '18 16:07

awj


People also ask

How do I set-ACL permissions in Windows using PowerShell?

This cmdlet is only available on the Windows platform. To use Set-Acl , use the Path or InputObject parameter to identify the item whose security descriptor you want to change. Then, use the AclObject or SecurityDescriptor parameters to supply a security descriptor that has the values you want to apply.


1 Answers

On my system i needed to use just IIS_IUSRS, so drop the BUILTIN\. Furthermore, I think you need to construct the FileSystemAccessRule with extra parameters inheritanceFlags and propagationFlags to get what you want.

Try this:

$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl = Get-ACL "C:\tmp"
$acl.AddAccessRule($accessRule)
Set-ACL -Path "C:\tmp" -ACLObject $acl

See: https://msdn.microsoft.com/en-us/library/sfe70whw(v=vs.110).aspx

like image 88
Theo Avatar answered Sep 28 '22 05:09

Theo