Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 486
John Chapman Avatar asked Oct 01 '12 16:10

John Chapman


1 Answers

Check the cmdlet's bound parameters like so:

if (this.MyInvocation.BoundParameters.ContainsKey("Verbose"))
{
}
like image 189
Keith Hill Avatar answered Oct 11 '22 09:10

Keith Hill