Good afternoon,
I'm PS beginner and I'm just getting familiar with it. There is one thing I can't figure out. I supposed those two snippets will do exactly do same, but I've never been so wrong:
<#1st: #>
Get-Process | % { if($_.WorkingSet -gt 10MB) {Write-Host $_.Name -ForegroundColor Green} else {Write-Host $_.Name -ForegroundColor Green}}<#2nd#> $prc = Get-Process foreach ($proc1 in $prc) { if($proc1.WorkingSet -gt 10MB) { Write-Host $proc1.Name -ForegroundColor Red } else { Write-Host $proc1.Name -ForegroundColor green } }
1st one writes all processes (despite if their working set size) in Green, 2nd one writes all processes which have WS above 10MB in red, all other processes are written in green.
Could anyone please point out difference between these two scripts? I thought they'll do exactly the same thing.
Thank you in advance.
Stanley