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

前端 未结 5 1098
温柔的废话
温柔的废话 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:40

    Also available: Check the parameter '$VerbosePreference'. If it is set to 'SilentlyContinue' then $Verbose was not given at the command line. If it is set to '$Continue' then you can assume it was set.

    Also applies to the following other common parameters:

    Name                           Value
    ----                           -----
    DebugPreference                SilentlyContinue
    VerbosePreference              SilentlyContinue
    ProgressPreference             Continue
    ErrorActionPreference          Continue
    WhatIfPreference               0
    WarningPreference              Continue
    ConfirmPreference              High
    

    Taken from an MSDN blog page from long ago... so it should be relevant with relatively old versions of Powershell. Also see "Get-Help about_CommonParameters" in Powershell v4.

提交回复
热议问题