How to handle $null in the pipeline

后端 未结 4 1007
北恋
北恋 2021-02-05 07:25

I often have the following situation in my PowerShell code: I have a function or property that returns a collection of objects, or $null. If you push the results in

4条回答
  •  感情败类
    2021-02-05 07:43

    Another possibility:

    $objects | Foreach-Object -Begin{If($_ -eq $null){continue}} -Process {do your stuff here}
    

    More info in about_Continue

提交回复
热议问题