I am trying to change the folder permission using below code but after executing the Inheritance From is showing both None and the parent drive.
also Principal like Everyone and one user is missing the entries with inherited from H:\
Please let me know what is the issue in my code.
# Get the drive letter that you want to remove "Authenticated Users" from.
#$systemDrives = Get-PSDrive -PSProvider FileSystem | where {($_.Name -ne "C") -and ($_.Name -ne "S")}
$systemDrives = Get-PSDrive -PSProvider FileSystem | where {($_.Name -eq "H")}
foreach($driveLetter in $systemDrives)
{
# Define the folder path
#$folderPath = "H:\"
$path = $driveLetter.Root
# Define the username for the authenticated user
$username = "Authenticated Users"
icacls $path /remove:g 'Authenticated Users(M,W)'
# Grant the permissions
icacls $path /grant:r 'Authenticated Users:(RX)'
icacls $path /grant:r 'Authenticated Users:(OI)(CI)(RX)'
icacls $path /grant:r 'Authenticated Users:(R)'
icacls $path /grant:r "Everyone:(R)"
# Get the existing access control list (ACL) for the folder
$acl = Get-Acl -Path $path
#protect the rules and not preserve inheritance
$acl.SetAccessRuleProtection($false, $true)
# Apply the modified ACL to the folder and all its subdirectories
Get-ChildItem -Path $path -Recurse | ForEach-Object {
$_ | Get-Acl | Set-Acl -AclObject $acl}
Write-Host "Inheritable permissions have been applied to all child objects in $path."
}
