0

I know this:

how to script out all the permissions in a folder using powershell?

$Acl = Get-Acl "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER01\MSSQL\DATA"
Set-Acl "C:\Program Files\Microsoft SQL Server\test" $Acl

But how, instead of copying and overwriting the current permissions on the target folder, just add the complementary permissions?

Something like, copying all permissions from source to target, but leaving the existent permissions of target remain there.

at the end the target folder will have all of its previous permissions plus all the permissions on source folder.

Marcello Miorelli
  • 3,368
  • 4
  • 44
  • 67
  • Get existing permissions for target, add the new ones, apply the complete set. There's examples out there for this but also there's a PS module available to make these tasks easier. I'll look up the name tomorrow. – Scepticalist Sep 05 '19 at 18:07
  • it would be very helpful if you could, please – Marcello Miorelli Sep 05 '19 at 18:23

1 Answers1

0

Get-ACL the permissions from the destination, then add the source permissions to it, then re-apply to the destination

Here's an example to add just a single permission:

$NewFolderRule = New-Object  System.Security.AccessControl.FileSystemAccessRule("MyDomain\Domain Admins","FullControl","ContainerInherit,ObjectInherit","None","Allow")

$DestinationFilePath = 'c:\temp'

$DestinationACL = Get-ACL $DestinationFilePath
$DestinationACL.AddAccessRule($NewFolderRule)
Set-ACL -Path $DestinationFilePath -AclObject $DestinationACL

...however this Powershell module makes life a lot easier and is worth using:

NTFS Security PS Module

Scepticalist
  • 3,737
  • 1
  • 13
  • 30