Mods Template/Function Grant-ModsPath ($GrantPath)

pull/257/head
KnifMelti 2023-01-10 23:53:15 +01:00
parent a3cd22a8eb
commit 4be19a4222
2 changed files with 25 additions and 0 deletions

View File

@ -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 #>

View File

@ -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
}