Given a list of items in PowerShell, how do I find the index of the current item from within a loop?
For example:
$letters = { \'A\', \'B\', \'C\' }
For those coming here from Google like I did, later versions of Powershell have a $foreach automatic variable. You can find the "current" object with $foreach.Current
$foreach
$foreach.Current