Here's a script that might help you. Test it out on a small number of folders and verify that resetting the inheritance is what you want it to do.
If you have multiple levels of folders that you do not have access to, then you will need to run this script multiple times to get to all of the files/folders.
cls
$noaccess = @()
$all = Get-ChildItem c:\temp\zzzz -recurse -Force -ErrorAction SilentlyContinue # set folder path here
foreach ($f in $all){
$f.fullname # show what we are processing
try {
$a = Get-Acl $f.fullname -ErrorAction Stop
if ($a.access.Count -eq 0) { # no acls!!!!
$noaccess += $f.fullname # add to the fix list
"No acls, adding to noaccess list."
}
} catch {
"Unable to access, adding to noaccess list."
$noaccess += $f.fullname
}
}
""
"Here are the files and folders we could not access."
$noaccess
if ((Read-Host "Enter y to fix") -ne 'y') {return}
# Now fix the problem, you must be running this script with UAC admin access
foreach ($f in $noaccess) {
"takeown.exe /f $f"
takeown.exe /f "$f"
"icacls.exe $f /reset"
icacls.exe "$f" /reset
}