[CmdletBinding()] param ( [Parameter()] [string] $Path, [Parameter()] [string] $PsxList ) $Header = (Get-Content -Path $PsxList -TotalCount 1).Split(';') $Csv = Import-Csv $PsxList -Delimiter ';' -Header $Header $FileList = Get-ChildItem -Path $Path -Filter "*.psv" $GameIdLength = 8 ForEach ($FileName in $FileList) { $GameId = $FileName.Name.Substring(2, 2 + $GameIdLength) $UniqueId = $FileName.Name.Substring(2 + 2 + $GameIdLength) $Title = $csv | Where-Object { $_.GameID -eq $GameId} if($Title.Length -gt 0) { if($UniqueId.Length -gt 0) { $NewName = "$($Title.Name)_$UniqueId" } else { $NewName = $Title.Name } Write-Host "Renaming $($FileName.Name) to $NewName" Rename-Item -Path $FileName -NewName $NewName } }