ファイルの名前を一括で変更する単純な PowerShell スクリプトがあり、変更を示すために「古いファイル名」と「新しいファイル名」を示すテーブル出力が必要です。「ForEach-Object」ループ内で新しいファイル名にアクセス/参照するにはどうすればよいですか? $_ の特定の値を更新できますか? 私は自分の変数 $newname を作成したので、それを使用したくありません。これは、ファイル名が実際に変更されたことを示す出力であるはずなので、システムから決定されたファイルの新しい名前にアクセスしたいと思います。脚本。
Write-Host "Old Name `t`t`t`t`t`t New Name"
Write-Host "-------- `t`t`t`t`t`t --------"
$files = Get-ChildItem -Path C:\Users\<user>\Desktop\Config
$files | % ({
    if ((!$_.PsIsContainer) -and ($_.Extension -eq '')) {
        $oldname =  $_.FullName
        $newname = "$($_.FullName).cfg"
        Rename-Item $oldname $newname
        # $_.Name still refers to the old file name without the extension
        # How do I immediately access its new name (including extension)?
        Write-Host $_.Name `t`t`t`t`t`t $newname
    }
})