Rename-Item
パイプコマンドレットで名前付きパラメーターを指定せずにスクリプト ブロックを使用すると、パラメーター バインディングが失敗する理由についての説明を探しています。
なぜこれが機能するのですか:
dir file.txt | ren -path {$_.name} -newname {$_.name -replace 'txt','doc'}
しかし、これは機能しません:
dir file.txt | ren {$_.name} {$_.name -replace 'txt','doc'}
?
エラー:
Rename-Item : A positional parameter cannot be found that accepts argument '$_.name'.
At line:1 char:19
+ dir file.txt | ren <<<< {$_.name} {$_.name -replace 'txt','doc'}
+ CategoryInfo : InvalidArgument: (:) [Rename-Item], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.RenameItemCommand
構文はRename-Item
私には非常に簡単に思えます (つまり、2 つの必須の位置パラメーター)。
SYNTAX
Rename-Item [-Path] <string> [-NewName] <string> [-Credential <PSCredential>] [-Force] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]