I'm most likely wrong but wouldnt this give you C on index 0. $strLetter [2]
@ the beach now ;) but will check it when I get home. PowerGUI gives you this info easy when debuging On Aug 14, 2013 7:07 PM, "Aakash Shah" <[email protected]> wrote: > Is there an elegant way to get the current position in a ForEach loop > without needing to initiate a variable and then increment it on each > iteration?**** > > ** ** > > For example, if I have the code below:**** > > ** ** > > $arrLetters = @("a", "b", "c", "d")**** > > ** ** > > foreach ($strLetter in $arrLetters)**** > > {**** > > Write-Host $strLetter**** > > }**** > > ** ** > > In this example, if the loop reaches “c”, is there some built in method to > discover that the current iteration loop is # 2 (or #3 if the index starts > at 1 instead of 0).**** > > ** ** > > It’s not necessarily a problem to initiate a “counter” variable, but I was > just curious to know if there is a cleaner way.**** > > ** ** > > I am using PowerShell 3 in case that helps.**** > > ** ** > > Thanks!**** > > ** ** > > -Aakash Shah**** > > ** ** > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1
