Powershell Sort-Object Name with numbers doesn’t properly

Question:

I am trying to find .sql files in a folder and filtering them based on the last write time. Based on the last write time I got 4 files as output.

Now when my command tries to do sort-object I am seeing Testscript10 at the top instead of TestScript5, how do I fix this issue?

My Code

$File Output

Answer:

Thanks for all your suggestions above for my question. After streamlining the suggestions, the code below worked well for my situation. This is helping me sort in the natural order like Windows Explorer does.

Source:

Powershell Sort-Object Name with numbers doesn’t properly by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply