title: Rename-item Powershell
body: <pre><code>Invoke-Command -ComputerName comp1,comp2 -ScriptBlock {Get-ChildItem F:\sktest\*.txt | ForEach-Object{
  $a=$_.fullname
  $b=$a.Substring(0,($a.Length-4))+"_old.txt" | %{
     Rename-Item -path $a -NewName $b}
  }}
  </code></pre>
  
  <p>While using the above piece of code to rename files(e.g. abc.txt to abc_old.txt),powershell is throwing "Cannot bind argument to parameter 'NewName' because it is null." error.</p>
  
  <p>When i print the results of $a and $b before the last pipeline, the result is coming as expected.However it is failing with the rename-item cmdlet at the end. Please let me understand the mistake im doing here.</p>