title: Get index of current item in a PowerShell loop
body: <p>Given a list of items in PowerShell, how do I find the index of the current item from within a loop?</p>
  
  <p>For example:</p>
  
  <pre><code>$letters = { 'A', 'B', 'C' }
  
  $letters | % {
    # Can I easily get the index of $_ here?
  }
  </code></pre>
  
  <p>The goal of all of this is that I want to output a collection using <a href="https://docs.microsoft.com/da-dk/powershell/module/Microsoft.PowerShell.Utility/Format-Table" rel="noreferrer">Format-Table</a> and add an initial column with the index of the current item. This way people can interactively choose an item to select.</p>