в .net есть методы всякие разные
Код:

gc $file | % {
$uri = [Uri]$_
if (-not $uri.Segments -or -not ($fn = $uri.Segments[-1])) { return }
[pscustomobject]@{
FN = [IO.Path]::GetFileNameWithoutExtension($fn)
E = [IO.Path]::GetExtension($fn)
S = $_
}
} | group FN | % {
[array]$mp4 = $_.Group | ? E -eq '.mp4'
if ($mp4.length) { $mp4[-1].S}
else { $_.Group[-1].S }
} | out-file ($file + '___.txt') -enc default