Question: Is there any possibility to get the number of a $\_. Variable in a foreach pipe?

Example:

```
$a = 1..9
$a | foreach {if ($_ -eq 5) { "show the line number of $_"}}

```

I hope you know what i mean.

Thanks!

Answer: 
**[Array.IndexOf Method](https://msdn.microsoft.com/en-us/library/system.array.indexof(v=vs.110).aspx)** (`.NET` Framework)

> 
> Searches for the specified object and returns the index of its first
>  occurrence in a one-dimensional array or in a range of elements in the
>  array.
> 
> 
> 

**Examples**:

```
PS D:\PShell> $a = "aa","bb","cc","dd","ee"

PS D:\PShell> $a.IndexOf('cc')
2

PS D:\PShell> $a=101..109

PS D:\PShell> $a.IndexOf(105)
4

PS D:\PShell> $a |foreach {if ($_ -eq 105) {"$($a.IndexOf($_)) is the line number of $_"}}
4 is the line number of 105

PS D:\PShell> 

```
For the original question as it sounds:

```
foreach ($x in 1..10) {
  Write-Host "Current item number is $($foreach.current)"
}

```