title: Error when I want to rename the files generated in a for loop in powerShell
body: <p>Here is my for loop</p>
  
  <pre><code>function Generate_bin($input_1, $bin_file_name, $Codes){
  
     $counter=1 
     foreach ($Code in $Codes)
     {
        Write-Host "Code = $Code" 
        $input_11 = "$input_1" + "$counter"
        $pattern = "0x"
        $New = ""
        $Code = [regex]::replace($Code, $pattern, "$New")
        $bin_file_name2 = "$bin_file_name"
        $bin_file_name2 += "$Code" + ".bin"
        #This utility generates "out.bin"
         Invoke-Command -ScriptBlock {.\xyz.exe -i -t "$input_1"}
  
        Rename-Item out.bin -NewName $bin_file_name2
        $counter++
     }
  
  }
  </code></pre>
  
  <p>I am getting following error </p>
  
  <pre><code>Rename-Item : Cannot create a file when that file already exists.
  At C:\script\myParser_unique.ps1:18 char:7
  +       Rename-Item out.bin -NewName $bin_file_name2
  +       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (C:\Users\v-ashi...Unified\out.bin:String) [Rename-Item], IOException
      + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
  </code></pre>