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

Powershell

Avatar of undefined
Last Comment
staino1983
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
Avatar of Qlemo
Qlemo
Flag of Germany image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of staino1983
staino1983

ASKER

resolved myself
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo