Link to home
Start Free TrialLog in
Avatar of staino1983
staino1983

asked on

powershell: set-acl to UNC path removes existing permissions

Hi

When I try and set "ReadPermissions" for a security group to a UNC path - eg \\computer\test, the group is added with the required permissions. However the existing permissions are all removed.

If I run the script against the local drive, eg c:\test, the permissions are not deleted.

How do I keep the existing permissions when applying the script to a UNC path?

Please note that I have to use UNC path and can not do local drive or use C$

Regards


$folder = "\\computer\test"
$ADgroup = "AD_GROUP"

$ACL = get-acl $folder
$accessLevel = "ReadPermissions"
$inheritanceFlags = "None"
$propagationFlags = "none"
$accessControlType = "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($ADgroup,$accessLevel,$inheritanceFlags,$propagationFlags,$accessControlType)
$Acl.AddAccessRule($accessRule)
Set-Acl $folder $Acl

Open in new window

Avatar of x-men
x-men
Flag of Portugal image

this will add the new FileSystemAccessRule to the colection retrieved from the folder:

$ACL = $ACL.Access + $accessRule
All examples I've seen talk about using $acl.SetAccessRule, not .AddAccessRule, to add ACLs. Try that.
ASKER CERTIFIED SOLUTION
Avatar of staino1983
staino1983

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of staino1983
staino1983

ASKER

resolved myself