2

So, I've recently lost a 400GB VHDX image due to ReFS Enforced Integrity Streams (details on question How to turn ReFS “Enforced” file integrity off?).

So now I am trying to disable the Enforced option on all my other, more important, files. Millions of files, through deep directory structures that often exceed the 256 character "limit" on full path names.

But the "naive" solution Get-ChildItem -Path "X:\" -Recurse | Set-FileIntegrity -Enforce $False throws a ScriptCallDepthException.

Everywhere I search, even on Microsoft own Blogs and documentations, suggest the Get-ChildItem -Recurse command. But it is of no use in this situation.

What's the way to go, then?

NothingsImpossible
  • 1,014
  • 4
  • 11
  • 23

1 Answers1

2

If you are hitting this limit you may not be using Powershell V3.

Try using the "trampoline" method with a stack. The script below only prints the file names, so modify it for your case.

$stack = New-Object System.Collections.Stack
#Load first level
Get-ChildItem -Path "YOUR-PATH-HERE" | ForEach-Object { $stack.Push($_) }
#Recurse
while($stack.Count -gt 0 -and ($item = $stack.Pop())) {
    if ($item.PSIsContainer)
    {
        Write-Host "Recursing on item $($item.FullName)"
        Get-ChildItem -Path $item.FullName | ForEach-Object { $stack.Push($_) }
    } else {
        Write-Host "Processing item $($item.FullName)"
    }
}
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • My Powershell version as returned by `$PSVersionTable.PSVersion` is 5.1. In my earlier research, I've found that the difference between V1 and V3 is just the stack size (100 vs. 1000 entries), so it still crashes, but at a later stage. So I reckon that even on V3+, the "trampoline" method is needed. I'm gonna try it and report back. – NothingsImpossible Jun 17 '20 at 13:45
  • I'm back. I'm going to have to modify it to treat >256-character paths, read-only files, etc. so I made a github repo for it: https://github.com/caioycosta/unenforce-refs-integrity . Unfortunately my Hard Disk died before I could be able to run this so I've just lost everything... but will carry on the work so I don't have the same problem in the future. – NothingsImpossible Jul 23 '20 at 12:51
  • Good luck in the future. – harrymc Jul 23 '20 at 14:01