Created
September 7, 2011 05:40
-
-
Save MikeLarned/1199853 to your computer and use it in GitHub Desktop.
Orchard - Set Folder Permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-Permissions { | |
param( | |
[string]$siteFolder, | |
[string]$userName | |
) | |
$folders = @("App_Data", "Themes", "Modules", "Media") | |
foreach($f in $folders) { | |
Write-Host "Setting Read/Write Access for $f" | |
Set-UserAccess -Path "$siteFolder\$f" -Permission "Write" -User $userName | |
Set-UserAccess -Path "$siteFolder\$f" -Permission "Read" -User $userName | |
} | |
} | |
#http://cyrusbuilt.net/wordpress/?p=158 | |
function Set-UserAccess { | |
param ( | |
[String]$Path, | |
[String]$User, | |
[String]$Permission | |
) | |
if (Test-Path -Path $Path -PathType Container) { | |
## Get the current ACL. | |
$acl = Get-Acl -Path $Path | |
## Setup the access rule. | |
$allInherit = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit", "ObjectInherit" | |
$allPropagation = [System.Security.AccessControl.PropagationFlags]"None" | |
$AR = New-Object System.Security.AccessControl.FileSystemAccessRule($User, $Permission, $allInherit, $allPropagation, "Allow") | |
## Check if Access already exists. | |
if ($acl.Access | Where { $_.IdentityReference -eq $User}) { | |
$accessModification = New-Object System.Security.AccessControl.AccessControlModification | |
$accessModification.value__ = 2 | |
$modification = $false | |
$acl.ModifyAccessRule($accessModification, $AR, [ref]$modification) | Out-Null | |
} else { | |
$acl.AddAccessRule($AR) | |
} | |
Set-Acl -AclObject $acl -Path $Path | |
Return $true | |
} else { | |
Return $false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment