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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Setting ReadOnly FTP in IIS7 with Powershell
Posted in Hosting & IIS7, Windows Powershell | No Comment | 3,940 views | 16/12/2010 22:16

Powershell function to set ReadOnly FTP in IIS7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Function Set-ReadOnlyFTP
{
Param ($FTPUsername, $ACLRule, $Path)
 
    If ($ACLRule -eq "ReadOnly")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$FTPUsername")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
 
    If ($ACLRule -eq "Modify")
    {
	    $Account = New-Object System.Security.Principal.NtAccount("$FTPUsername")
	    $ACL = Get-Acl -Path "$Path"
	    $Permission = "$Account","Modify","ContainerInherit,ObjectInherit","None","Allow"
	    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $Permission
	    $ACL.SetAccessRule($AccessRule)
            $ACL | Set-Acl "$Path"
    }
}

I won’t explain arguments because they are clear to understand.



Leave a Reply