Thanks to bad, old code, Microsoft’s PowerShell breaks on file or directory paths longer than 248 characters. PowerShell reuses other code that maintains compatibility with very old software that can’t understand paths with more than 260 characters. I don’t know how 260 drops to 248 in PowerShell, but it does.
Amazingly, in the first comment in a bug report, Microsoft dodges the question and passes the buck.
I hit this bug when working with a Sitecore web site. For example, I have a path like this:
That is 259 characters. I can’t delete it with PowerShell’s Remove-Item command.
Fortunately, there is a workaround: use legacy command prompt tools. In my case, I am trying to remove everything below C:\XXXXXXXXXXXXXXX\raw\, so I can use this command in PowerShell:
cmd /c rmdir C:\XXXXXXXXXXXXXXX\raw\ /s/q
But I shouldn’t have to do this. There is no reason that PowerShell can’t delete files with more than 248 character paths.