Is it possible to check if -Verbose argument was given in Powershell?

前端 未结 5 1097
温柔的废话
温柔的废话 2021-02-07 02:35

I have written my own Powershell logging function Log with parameters stream (on which stream to write the message) and message (the messa

5条回答
  •  遥遥无期
    2021-02-07 02:43

    More generally: since one might specify -Verbose:$false on the command line, the following code handles that case. It also works for any other switch parameter:

    $Verbose = $false
    if ($PSBoundParameters.ContainsKey('Verbose')) { # Command line specifies -Verbose[:$false]
        $Verbose = $PsBoundParameters.Get_Item('Verbose')
    }
    

提交回复
热议问题