title: Rename-Item error: Cannot rename because item does not exist
body: <p>I have the following powershell code, which is attempting to rename all SQL files in a folder, adding a unique prefix to each file e.g. the first prefix will be '1001 - sp - C - ':</p>
  
  <pre><code>gci -Path 'C:\FolderToLookIn' -Exclude "1*" | ForEach-Object {
      New-Object PSObject -Property @{
          'LineNumber' = $linenumber;
          'Name'       = $_.Name;
          'Extension'  = $_.Extension
      };
      $linenumber++
  } | Where-Object {
      $_.Extension -eq ".sql"
  } | Rename-Item -NewName {$_.LineNumber.ToString("1000") + ' - sp - C - ' + $_.Name}
  </code></pre>
  
  <p>However, this produces errors such as the following:</p>
  
  <blockquote>
    <p>Rename-Item : Cannot rename because item at '@{Extension=.sql; LineNumber=22; Name=sp_Firm_GetAll.sql}' does not exist.</p>
  </blockquote>
  
  <p>So, how can I add the <code>LineNumber</code> property and use it as a prefix in the <code>Rename-Item</code> command without losing the item itself?</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>I have also tried the following, passing through the <code>FullName</code> and using this in the <code>Rename-Item</code>:</p>
  
  <pre><code>gci -Path 'C:\FolderToSearch' -Exclude "1*" | ForEach-Object {
      New-Object psObject -Property @{
          'LineNumber' = $linenumber;
          'Name'       = $_.Name;
          'Extension'  = $_.Extension;
          'FullName'   = $_.FullName
      };
      $linenumber++
  } | Where-Object {
      $_.Extension -eq ".sql"
  } | Rename-Item -Path $_.FullName -NewName {$_.LineNumber.ToString("1000") + ' - sp - C - ' + $_.Name}
  </code></pre>
  
  <p>However, this errors also:</p>
  
  <pre>
  Rename-Item : Cannot bind argument to parameter 'Path' because it is null.
  At line:3 char:19
  + Rename-Item -Path $_.FullName -NewName {$_.LineNumber.ToString("1000") + ' - sp
  </pre>