Disable inheritance and manually apply permissions when creating a folder in Powershell

I’m trying to script the creation of subfolders, all of which will need to have inheritance broken and custom security permissions applied.

I’ve got the folder creation bit sorted, it’s just the permissions that tripping me up. Am I right in thinking that I can point to a folder and get those permissions replicated over to the new one? That’s what I am trying to do with the line Get-Acl “O:CustomersExampleSensitiveFolderPermissions”

foreach($folder in (gci 'O:Customers' -directory)) { new-item -ItemType directory -Path ($folder.fullname+"Contracts") new-item -ItemType directory -Path ($folder.fullname+"NDA") new-item -ItemType directory -Path ($folder.fullname+"Sensitive") $acl = Get-Acl "O:CustomersExampleSensitiveFolderPermissions" # SetOwner $acl.SetOwner([System.Security.Principal.NTAccount] $env:USERNAME) # Write updated ownership info back Set-Acl $FolderPath $acl | Out-Null # SetAccessRuleProtection $acl.SetAccessRuleProtection($True, $True) # Write updated ACL back Set-Acl $FolderPath $acl | Out-Null } 

The error I am getting is

Set-Acl : Cannot bind argument to parameter ‘Path’ because it is null. At line:9 char:11 + Set-Acl $FolderPath $acl | Out-Null + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-Acl], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAclCommand

submitted by /u/12Bore
[link] [comments]

Leave a Reply