Removing a permission in powershell

Hi all, I am trying to remove a specific special permission from a ACL. In this example the Delete subfolders and files permission already assigned to the marketing group. When I run the script it removes the permission (win) but then creates a new ACE for marketing granting them the permission (WTF?). So I am obviously failing somewhere or just going about this completely wrong. So anyone that can assist please help and if its not to much trouble could you send script corrections or replacements using full syntax and no alias's as I am trying to learn as I go. Thanks in advance

# Set Variables
$file = 'D:\TestFolder2'
$UserGroup = 'Domain\Marketing'
$permset1 = 'DeleteSubdirectoriesAndFiles'

# List permissions you would like to remove
$colRights = [System.Security.AccessControl.FileSystemRights]"$permset1"

# Select user \ group
$objUser = [System.Security.Principal.NTAccount]"$UserGroup"

# Create the new ACL
$objACE = [System.Security.AccessControl.FileSystemAccessRule] "$objUser, $colRights"
$objACL = Get-ACL "$file"
$objACL.RemoveAccessRule($objACE)

# Apply the ACL
Set-ACL $file $objACL
Dead_EyesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Network ZeroCloud Engineer Commented:
try running it like that

# Set Variables
$file = 'D:\TestFolder2'
$UserGroup = 'Domain\Marketing'
$permset1 = 'DeleteSubdirectoriesAndFiles'

# List permissions you would like to remove
$colRights = [System.Security.AccessControl.FileSystemRights]"$permset1"
0
Dead_EyesAuthor Commented:
Errors out with no action :(
0
Dead_EyesAuthor Commented:
Problem was I missed Inheritance so was failing to be exact and I needed to use a UNC path. Correct script is as follows:
$file = 'Server\drive$\Path'
$UserGroup = 'Domain\Marketing'
$permset1 = 'DeleteSubdirectoriesAndFiles'

# List permissions you would like to remove
$colRights = [System.Security.AccessControl.FileSystemRights]"$permset1"

# Specify Inheritance
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None

# Specify permission type
$colrights = [System.Security.AccessControl.AccessControlType]::Allow

# Select user \ group
$objUser = [System.Security.Principal.NTAccount]"$UserGroup"

 # Create the new ACL
$objACE = System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objtype)
$objACL = Get-ACL "$file"
$objACL.RemoveAccessRule($objACE)

 # Apply the ACL
 Set-ACL "$file" $objACL
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dead_EyesAuthor Commented:
No other suggestions and worked it out for myself
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.