Hello, I have a script that checks files/folders for their permissions and determines if they should be allowed on that folder.
The issue I’m running into is, say I give c:\test 2 different permissions
full control for ‘this folder only’ and
read&execute for ‘This folder, subfolders and files’
The function gets passed as
get-generalusers $path $permissions (get-generalusers “c:\test” $regex #where regex = the regex for read and execute)
if(((get-acl $path).access | ?{$_.identityreference -eq $user}).count -gt 1)
{
$trigger = $false
foreach($acl in (get-acl $path).access | ?{$_.identityreference -eq $user} | ?{$_})
{
foreach($aclmulti in $acl | %{$_.FileSystemRights})
{
write-host "before changes!"
$acl
if($aclmulti -notmatch $permissions)
{
try
{
$x = (get-acl $path)
$x.removeaccessrule($acl)
write-host " removing: "
$acl
write-host "With permissions: "
write-host $aclmulti
set-acl $path -aclobject $x -erroraction stop
write-host "$user has been removed from $path"
}
catch
{
write-host "Failed to remove $user from $path due to " + $error[0].exception.message
$trigger = $true
$badgrab+=@("$user is a general user with improper permissions")
}
}
}
}
I get to this line section of code, which should remove just the user that has too many permissions, and it does…but then it changes from ‘this folder, subdirectoires and files’ to just ‘subdirectories and files only’
Why is it changing the ‘apply to’ type?
Ignore the write-host’s those were just for troubleshooting purposes.
easy way to test
$path = “c:\test”
#ready only or less
$permissions = “^(read(Execute|File|Data|Extended|Attributes|Permissions|And)+|Synchronize|\s|,|-1610612736)+$”
$user = “Builtin\Users”
Then create a folder c:\test, with users with full control with ‘this folder only’ and users with read&execute on ‘This folder, subdirectories and files’ and run that code snippet.
You’ll see it changes the user with read&execute from ‘this folder, subdirectories and files’ to subdirectories and files’ when I want it to keep it’s original type…
It appears it’s changing it’s changing it’s propagationflags from ‘none’ to ‘InheritOnly’.
I’m not sure why, I thought I was just removing it from the list, why is it changing the propagationflags? Or is there a better way to do this?