search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Hosting & IIS7, Windows Powershell | No Comment | 2,814 views | 11/12/2010 01:18

Very detailed script about how to set ACL for IIS users.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Function Set-IISACL
{
Param ($Username, $LogDir)
 
    $Account = New-Object System.Security.Principal.Ntaccount("$Username")
    $Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
    $ACL = Get-Acl -Path "$LogDir"
    $ACL.SetAccessRuleProtection($True, $True) 
    Set-Acl -Path "$LogDir" -AclObject $ACL
    $Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
    $ACL.SetAccessRule($AccessRule)
    $ACL | Set-Acl "$LogDir"
 
    $Account = New-Object System.Security.Principal.Ntaccount("$Username")
    $Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
    $ACL = Get-Acl -Path "$LogDir\db"
    $Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
    $ACL.SetAccessRule($AccessRule)
    $ACL | Set-Acl "$LogDir\db"
 
    $Account = New-Object System.Security.Principal.Ntaccount("$Username")
    $Sid = $Account.Translate([System.Security.Principal.SecurityIdentifier])
    $ACL = Get-Acl -Path "$LogDir\http\upload"
    $Permission = "$Account","modify","ContainerInherit,ObjectInherit","None","Allow"
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
    $ACL.SetAccessRule($AccessRule)
    $ACL | Set-Acl "$LogDir\http\upload"
}

Contains example for Modify and Read Only permissions.