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\' }
I am not sure it's possible with an "automatic" variable. You can always declare one for yourself and increment it:
$letters = { 'A', 'B', 'C' } $letters | % {$counter = 0}{...;$counter++}
Or use a for loop instead...
for
for ($counter=0; $counter -lt $letters.Length; $counter++){...}