'How to glob files into folders depending on their prefix

I have 4000 fish picture files, named as follows:

acanthistius_cinctus_1
acanthistius_cinctus_2
acanthopagrus_latus_1
acanthopagrus_latus_2
...

There are 468 species.

In order to train a computer vision model, I need to group these files to have a folder for each species with related picture inside.

Like this :

acanthistius_cinctus/ 
                     acanthistius_cinctus_1
                     acanthistius_cinctus_2

I need a PowerShell script because I'm a bit lost with other types of scripts.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source