We have several servers in the same domain and the requirement is to remove permission from a specific folder which is defined in the power-shell script and I need to specify the name of the object that Im going to delete and list of the servers (Given a path in the text file is also okay).Is this possible to achieve this task via power shell ?
Eg : Defined Path (C:\Powershell) , Object name on security tab(myname@domain.com),List of servers (SERVER01,Server02)
Also this was the script that I tried
$path = "C:\Powershell"
$users = @{}
$users = Get-NTFSAccess $path | Where-Object {$_.Account -ne "DOMAIN\Exclude"} | Select-Object Account
foreach ($user in $users) {
$removalAccount = $user.Account
Write-Host "Removing account - $($removalAccount)"
Remove-NTFSAccess -Path $path -Account $removalAccount -AccessRights FullControl -AccessType Allow
Remove-NTFSAccess -Path $path -Account $removalAccount -AccessRights FullControl -AccessType Deny
}
Thanks !