
PowerShellで
・ファイル名を変更
できます!
コード
ここでは例として
・デスクトップ配下のファイル「aiueo.txt」のファイル名を変更
します。

# 変更前のファイルパス
$oldFileName="C:\Users\user\Desktop\aiueo.txt"
# 変更後のファイル名パス
$newFileName="C:\Users\user\Desktop\newFileName.txt"
$ws = New-Object -ComObject Wscript.Shell
try
{
# ファイル名を変更
Rename-Item $oldFileName $newFileName -ErrorAction Stop
$ws.popup("ファイル名を変更しました。")
}
catch
{
$ws.popup("エラー : " + $PSItem)
}
実行結果
ファイル名を変更できました。


参考①
フォルダ名の変更もできます。
詳細は以下の記事をご確認ください。
参考②
上記のコードで使用した以下の詳細は、公式サイトをご確認ください。
●「Rename-Item」コマンドレット
●例外処理について