Mods Template/Function Grant-ModsPath ($GrantPath)
parent
a3cd22a8eb
commit
4be19a4222
|
@ -44,6 +44,9 @@ $DelFile = @("")
|
|||
$CopyFile = ""
|
||||
$CopyTo = ""
|
||||
|
||||
#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2"
|
||||
$GrantPath = @("")
|
||||
|
||||
<# FUNCTIONS #>
|
||||
. $PSScriptRoot\_Mods-Functions.ps1
|
||||
|
||||
|
@ -75,5 +78,8 @@ if ($DelFile) {
|
|||
if ($CopyFile -and $CopyTo) {
|
||||
Copy-ModsFile $CopyFile $CopyTo
|
||||
}
|
||||
if ($GrantPath) {
|
||||
Grant-ModsPath $GrantPath
|
||||
}
|
||||
|
||||
<# EXTRAS #>
|
||||
|
|
|
@ -192,3 +192,22 @@ function Copy-ModsFile ($CopyFile, $CopyTo) {
|
|||
Return
|
||||
}
|
||||
|
||||
function Grant-ModsPath ($GrantPath) {
|
||||
foreach ($path in $GrantPath)
|
||||
{
|
||||
if (Test-Path "$path") {
|
||||
$NewAcl = Get-Acl -Path $path
|
||||
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
|
||||
if ((Get-Item $path) -is [System.IO.DirectoryInfo]) {
|
||||
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow'
|
||||
}
|
||||
else {
|
||||
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow'
|
||||
}
|
||||
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
|
||||
$NewAcl.SetAccessRule($fileSystemAccessRule)
|
||||
Set-Acl -Path $path -AclObject $NewAcl
|
||||
}
|
||||
}
|
||||
Return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue