PS script error

Hram Admin 120 Reputation points
2025-04-15T09:48:39.45+00:00

Hello!

I have a few scripts that delete old backups from some folders. There's actually one string that deletes the oldest folder:

Remove-Item -Path [Folder Name] -Recurse -Force

...and it works perfect for all folders except the one: while deleting this folder the script terminates with the error 0xC00000FC or - if run in ISE - the ISE itself exits and gets restarted.

This folder is different from any other only in containing user profiles, but the script is run with the #Requiers Administrator option so it must have the right to delete them.

Either script or ISE doesn't even delete anything - the folder size never changes, it seems the script just hangs for ~5-7 minutes and then crashes with 0xC00000FC.

What can be the cause of this?

Regards,
Michael

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,915 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Rich Matheisen 47,786 Reputation points
    2025-04-15T19:40:29.0333333+00:00

    It might be a damaged profile, or a profile with a very long name, or a profile with security that's unexpected. Or, it may be a damaged disk (perhaps a bad sector?).

    Sometimes just running with administrative privileges isn't sufficient (see unexpected security). Try running your script with backup and restore privileges.

    FYI, the Remove-Item will also remove (or try to) any sub-directories it encounters. Is that your intention?

    If you encounter a profile that's difficult to remove, you might want to try using delprof2 (https://helgeklein.com/free-tools/delprof2-user-profile-deletion-tool/).

    I don't think this is a PowerShell problem, though.


  2. Hram Admin 120 Reputation points
    2025-04-22T10:10:12.3633333+00:00

    "I don't think this is a PowerShell problem, though." - seems it is obviously PS bug:

    Test 1: PowerShell

    Remove-Item -Path D:\Backup\PROFILES\Personal\User1\Desktop\ -Recurse -Force

    Result: Always Hangs

    Test 2: CMD

    rd /S /Q D:\Backup\PROFILES\Personal\User1\Desktop\

    Result: Deleted

    0 comments No comments

  3. MotoX80 35,726 Reputation points
    2025-04-22T13:35:23.1566667+00:00

    I don't think that Remove-Item has an option to deal with symbolic links. Get-ChildItem has the -FollowSymlink switch to override its default. I suspect that you are running into the recursive "application data" feature.

    https://superuser.com/questions/1559693/robocopy-loops-nests-application-data-29-times-when-copying-application-data

    Remove-Item would need the equivalent of robocopy's /XJ or /XJD switches.

    From a command prompt you can run this to see what links are defined.

    dir D:\Backup\PROFILES\Personal\User1\Desktop\ /a /s | findstr "<JUNCTION>"
    
    
    

    I have not tested this, but I would think that you should be able to use Get-Childitem as a workaround.

    Get-ChildItem Path D:\Backup\PROFILES\Personal\User1\Desktop\ -Recurse | Remove-Item -Force 
    

  4. Hram Admin 120 Reputation points
    2025-04-24T08:24:22.17+00:00

    MotoX80, thank you so much for this - https://superuser.com/questions/1559693/robocopy-loops-nests-application-data-29-times-when-copying-application-data - I didn't know it!

    Regarding the problem with Application Data: I'm trying to delete the folders that do NOT contain Application Data (they are the folders created by another backup which does not copy Application Data) so I think it's not the case:01

    dir D:\16042025\Personal\User1\Desktop\ /a /s | findstr "<JUNCTION>"

    dir D:\16042025\Personal\User1\ /a /s | findstr "<JUNCTION>"

    • both returns nothing.

    Here are my tests:

    02

    -robocopy does list each object as excpected...

    04

    ...but Remove-Item seems not :(

    0 comments No comments

  5. Hram Admin 120 Reputation points
    2025-04-24T10:47:18.3466667+00:00

    Get-ChildItem Path $fdel.Name -Recurse | Remove-Item -Force did not hang, did not delete anything and displayed (I mean set Error[0]) PathTooLongException error.

    However I'm not sure if it is the root problem that makes Remove-Item crash /hang or not because (at least I think so) other folders that are being deleted by the script may also contain long names, but nevertheless they are deleted successfully...

    In any case it's rather strange to have problems with deleting files with long paths and do not have the same problems when copying that files to backup directory - theoreticaly the error should have arisen while copying first, not while deleting.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.