For a small number of files it works, unfortunately in the case of, say, 12000 files in several subdirectories either takes a very long time or does not end.
What do you mean with “takes a very long time”? I just checked it on my local computer on my slow HDD - not SSD - with a directory with more than 40,000 files in several subdirectories and it didn’t even take 6 seconds?!
Again … I tested it on a slow HDD with a folder with more than 40,000 files and it took 6 seconds (on PowerShell version 7). There might be an issue with your files
Is this a recurring task? At first you may switch to PowerShell version 7. That will already speed up this task.