Suppose you have a directory with corrupted filenames. You only know that they are all .png files, but the extensions have been renamed to random names. You would then like to rename everything to .png at once.
Using Windows PowerShell:
dir | % {ren $_ ($_.name.substring(0, $_.name.length-4) + ‘.png’ ) }
The first command, dir, gets a list of files from the current directory and passes objects (not text!) to the next command in the pipeline. The next one then (% means foreach-object) executes the block (between {e}) for each of the items.
In this case, the rename command passing the name ($_)
and the new name ($_.name.substring(0, $_.name.length-4) + ‘.png’ )
Source: link