1

$ll = @("a","b","c"); ForEach ($e in $ll) {Write-Host $_}

I've spent too much time on this already and I'm tired of searching and fiddling. Who wants to make me feel silly by explaining why this PowerShell code produces no output? No errors. Just 3 new blank lines.

Edit: I know what $_ is and what it's supposed to do. It's simply not working in this loop. Thx

3
  • 4
    $_ has a value only in a ForEach-Object pipeline. What you have here is a foreach loop. Use Write-Host $e -- you didn't declare that $e for nothing! Commented Feb 2, 2023 at 21:19
  • 1
    foreach and ForEach-Object are not the same, one is a language keyword the other is a cmdlet. $_ is auto populated in scriptblocks that process the current object, such as in the pipeline. Commented Feb 2, 2023 at 21:23
  • Please read the foreach documentation. Not sure how more clear could we be. Jeroen's comment should be clear enough. learn.microsoft.com/en-us/powershell/module/… Commented Feb 3, 2023 at 16:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.