Search code examples
c#powershellpowershell-cmdlet

In Custom C# PowerShell Cmdlet Identify If -Verbose Was Specified


I have a custom C# PowerShell Cmdlet (inheriting from the Cmdlet base class) and I want to be able to identify if the "-Verbose" parameter was specified when running the Cmdlet. I realize that WriteVerbose will output when the -Verbose parameter is specified, but I would like to actually do some other code when -Verbose is specified (i.e. not output the Console.Write values when -Verbose is specified).

Thanks,

John


Solution

  • Check the cmdlet's bound parameters like so:

    if (this.MyInvocation.BoundParameters.ContainsKey("Verbose"))
    {
    }