We are sending this link, I am trying to enter a verbose mode in my script.
When I have a function defined like this:
function TestVerbose { param( [switch]$verbose, [Parameter(Mandatory = $True)] $p1 ) if($verbose) { Write-Verbose "Verbose Mode" } } Get-Help TestVerbose
I get the following error:
Get-Help: A parameter named "Verbose" has been defined for some time for the command. On line: 12 char: 9 + Get-Help <<<<TestVerbose + CategoryInfo: MetadataError: (:) [Get-Help], MetadataException + FullyQualifiedErrorId: ParameterNameAlreadyExistsForCommand, Microsoft.PowerShell.Commands.GetHelpCommand
BUT, if I define a function like this [removing the required parameter attribute], it works fine
function TestVerbose { param( [switch]$verbose, $p1 ) if($verbose) { Write-Verbose "Verbose Mode" } } Get-Help TestVerbose
Any idea why this behavior? I want to keep the required switch and want the user to execute my function as follows:
TestVerbose -verbose
Angshuman agarwal
source share