Clear captured output/return value in a Powershell function

前端 未结 8 659
灰色年华
灰色年华 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:24

    Set variable scope to script or global.

    function Get-Greeting {
        'Hello Everyone'
        $greeting = 'Hello World'
        'Ladies and Gentlemen'
        $script:greeting = $greeting
    }
    
    Get-Greeting
    $greeting <== 'Hello World'
    

提交回复
热议问题