Clear captured output/return value in a Powershell function

前端 未结 8 672
灰色年华
灰色年华 2021-01-01 23:33

Is there a way to clear the return values inside of a function so I can guarantee that the return value is what I intend? Or maybe turn off this behaviour for the function?<

8条回答
  •  半阙折子戏
    2021-01-02 00:11

    Pipe output to Out-Null, redirect output to $null, or prefix the function calls with [void]:

    $myArray.Add("Hello") | Out-Null
    

    or

    $myArray.Add("Hello") >$null
    

    or

    [void]$myArray.Add("Hello")
    

提交回复
热议问题