Since PowerShell does not have enough information to 'bind' to the parameters, ProcessRecord is not called at all, and instead gives an error. So you never see your switch getting executed.
Parameter set cannot be resolved using the specified named parameters. + CategoryInfo : InvalidArgument: (:) [], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,
You should not even want to. Let PowerShell handle the parameters. You can fix your CmdLet by doing the following:
- Remove the Position = 0 for the SwitchParameters. It's not logical to have positional SwitchParameters. PowerShell can detect SwitchParameters with ease in any position
- Do not make the SwitchParameters mandatory. It is of no use. The switch is either there or not, true or false. Forcing it to be there does not make sense. It's like forcing it to be true.
- Give your CmdLet a DefaultParameterSetName. Logical would be to chose one of the defined parameter sets, like 'Text'
- Make your Argument parameter Position = 0. Since the SwitchParameters don't need a position this is the first.
Now you can call it like this:
Get-SHA256 'SomeText'
Get-SHA256 'SomeText' -Text
Get-SHA256 -Text 'SomeText'
Get-SHA256 'C:\Some.File' -File
Get-SHA256 -File 'C:\Some.File'
etc
Also consider checking the SwitchParameters values instead of switching on the ParameterSetName. SwithParameters can be called like -File:$false. Fall back to your default.