Set-acl and remove-ntfs both fail from PowerShell yet i can do it from the GUI

I have put together a script that searches all of our folders then searches the folders for groups that should have access and do not and groups that should not have access and do.
Finding only the folders that need NTFS permissions changed works great.  Adding the groups that need added works great but removing groups is not working.  Below is a section of my script with the section not working underlined.  You can
see i have tried 2 approaches.  
If i use the Remove-NTFSAccess command (which i really prefer) I get no errors and you would think all worked until you check.
If i use set-acl about half give me a error  "Set-Acl : The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation" but it does not remove the Domain admins for any of the
folders including the ones that give no error.
I have privileges to do it.  I can go to a folder and remove the group from the NTFS permissions in the GUI with no issue. 
Thanks!
"Add Nseries Admins"
$workingdir = (Get-Content "$env:TEMP\Add nseries admins.txt")
$mynum=[int]$workingdir.Count
foreach ($path in $workingdir) {
$mynum
$mynum = $mynum - 1
$path
Add-NTFSAccess -Path "$path" -Account "SCHOOLS\Nseries Admins" -AccessRights FullControl -AccessType Allow -AppliesTo ThisFolderSubfoldersAndFiles
"Romeve Domain admins"
$workingdir = (Get-Content "$env:TEMP\Remove domain admins.txt")
$mynum=[int]$workingdir.Count
foreach ($path in $workingdir) {
$mynum
$mynum = $mynum - 1
$path
# Add-NTFSAccess -Path "$path" -Account "SCHOOLS\Nseries Admins" -AccessRights FullControl -AccessType Allow -AppliesTo ThisFolderSubfoldersAndFiles
# Remove-NTFSAccess -Path "$path" -Account "SCHOOLS\Domain Admins" -AccessRights Read -AccessType Allow -AppliesTo ThisFolderOnly
$acl=get-acl "$path"
$accessrule = New-Object system.security.AccessControl.FileSystemAccessRule("SCHOOLS\Domain Admins","Read",,,"Allow")
$acl.RemoveAccessRuleAll($accessrule)
Set-Acl -Path "$path" -AclObject $acl

I just ran that a couple of times.  No errors as long as the subfolders are not protected in a way the blocks the admin.  I will try and find a folder that causes this exact scenario.
Is it possible that this was fixed in V4?
¯\_(ツ)_/¯
The SACL being overwritten isn't fixed. There's a Connect bug
here. Set-Acl basically does this before trying to call SetAccessControl():
$path = "$env:Temp\temp_item_name"
$acl = Get-Acl $path
# Get the binary form:
$binaryForm = $acl.GetSecurityDescriptorBinaryForm()
# Create a new SD object:
$newacl = New-Object $acl.GetType()
# Take the old binary form and use it for the new SD object,
# but tell it it's for all sections, including the SACL:
$newacl.SetSecurityDescriptorBinaryForm($binaryForm, "All")
Next, it tries to call SetAccessControl() inside of a try{} block. If it detects a PrivilegeNotHeld exception, it will try to redo the section above without setting the Owner, Group, and SACL (if certain conditions are met). I can't get the second call to
error the way Lishron did, but that doesn't mean there's no scenario where that can't happen.
By the way, here's an example of trying to call SetAccessControl() with the modified SD object from above:
$FileSystemItem = Get-Item $path
$FileSystemItem.SetAccessControl($newacl) # <-- Fails if you're not an admin; overwrites SACL if you are
$FileSystemItem.SetAccessControl($acl) # <-- Succeeds (unless you're trying to change the owner)

Similar Messages

Maybe you are looking for

  • Spry Menu Fade In

    Is there a way to make the submenus of a horizontal navigation bar fade in? I would like something similar to this: http://www.gatewaychurch.com/

  • Auto Scaling thumbs in Mini Bridge really necessary?

    I would expect that opening up Mini Bridge would simply show more thumbs rather than automatically scaling 1 or 2 as big as possible. How is this useful? And how is it not annoying? I wish Mini bridge had a Scale Slider like its big brother has. Don'

  • E52 Auto Switch Off

    Dear All, I bought a New E52 Mobile, till last week it was working fine. But then my mobile started to switch off often. Can anyone help me on this. Regards, Shagul 

  • Can I save PDF's in a form where text can be edited by people that only have Adobe reader ?

    If I have Adobe acrobat can I save PDF's in a form where text can be edited by people that only have the free version of Adobe reader ? If so do I need a prof verion of Acrobat to do this ?

  • Display random image

    Hey all. Creating my first form in LiveCycle. Haven't a clue as to what I'm doing... maybe someone can help. I don't know javascript, so I usually just use trial and error until I figure it out... but I just can't get this to work. I have 20 images o