Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script Grant Full Access Permission on Multiple Folders and Sub-Folders

$
0
0

Hi, I'm having a issue trying to run this script. 

1.)It provides each folder with "Special" Permission over them. (Read, Write, Modify, Full control). Is there a way of making it "Full Control" Permission instead of special permission?

or

2.) Is there a way to make the Object Apply to "This Folder,sub folders and files" (when i change it manually this it changes to Full Control Access)?

What I tried doing in the following script is removing the inheritance of the folder then applying its level of authentication. I do get some errors and I'm pretty sure it's has to do with some files being password protected.

$domainG = "Domain\Group"
$dir = "X:\Folder\Folder\*\SameName"
$subfolder = Join-Path $dir "\*"
$subsubfolder = Join-Path $subfolder "\*"
$subsubsubfolder = Join-Path $subsubfolder "\*"
$subsubsubsubfolder = Join-Path $subsubsubfolder "\*"

$acl = Get-Item $dir |get-acl

#This removes inheritance
$acl.SetAccessRuleProtection($true,$true)
$acl |Set-Acl



# Gives full control
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @($domainG,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl

$acl = Get-Item $subfolder |Get-Acl
# This adds full control to the subfolder
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @($domainG,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl


$acl = Get-Item $subsubfolder |Get-Acl
# This adds full control to the sub sub folder
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @($domainG,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl

$acl = Get-Item $subsubsubfolder |Get-Acl
# This adds full control to the sub sub subfolder
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @($domainG,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl

$acl = Get-Item $subsubsubsubfolder |Get-Acl
# This adds full control to the sub sub sub subfolder
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @($domainG,"FullControl","Allow")
$acl.SetAccessRule($rule)
$acl |Set-Acl


Viewing all articles
Browse latest Browse all 15028

Trending Articles