I have the following code that should go through folders in a file archive and turn all permissions into read permissions. However, there is a problem: it does not replace existing permissions that are simply added to them. Secondly, if the folder does not receive inherited permissions, it gives an error message
Set-Acl: this process does not have the “SeSecurityPrivilege” privilege, which is required for this operation.
I checked the permissions and I have full control over them
function NotMigrated($SiteURL, $Folder) {
try {
$SiteString=[String]$SiteURL
$pos = $SiteString.LastIndexOf("/")
$Site = $SiteString.Substring($pos+1)
$parent=((get-item $Folder ).parent).Fullname
$AllFolders = Get-ChildItem -Recurse -Path $Folder |? {$_.psIsContainer -eq $True}
$FilesInRoot = Get-ChildItem -Path $Folder | ? {$_.psIsContainer -eq $False}
$acl= get-acl $Folder
foreach ($usr in $acl.access) {
$acl.RemoveAccessRule($usr)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($usr.IdentityReference,"Read","none","none","Allow")
$Acl.AddAccessRule($rule)
}
$acl | Set-Acl
} catch { continue }
foreach ($CurrentFolder in $AllFolders) {
$FolderRelativePath = ($CurrentFolder.FullName).Substring($Folder.Length)
$FileSource = $Folder + $FolderRelativePath
try {
$acl= get-acl $FileSource
foreach ($usr in $acl.access) {
$acl.RemoveAccessRule($usr)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($usr.IdentityReference,"Read","none","none","Allow")
$acl.AddAccessRule($rule)
}
$acl | Set-Acl
} catch { continue }
}
}
source
share