What is the best way to filter objects with no path?

First off I should note this is for my class homework. The question is use where-object and foreach-object to get a count of processes that are currently running but have no path. I have been struggling to write a statement that matches now empty paths. I tried

Get-Process | Where-Object {$_.path -match ‘ ‘} |
ForEach-Object -Begin { $nprocs1 = 0 } -process { $nprocs1++ } -end {write-host “Running processes $nprocs1”}

and

Get-Process | Where-Object {-not ($_.path -like “*”)} |
ForEach-Object -Begin { $nprocs1 = 0 } -process { $nprocs1++ } -end {write-host “Running processes $nprocs1”}

But neither work. Could anyone point me in the right direction?

submitted by /u/spicy_taco88
[link] [comments]

Leave a Reply