Mar 11 2021 12:09 PM
Is there a way to add a parameter to a script that would work like -Force or -Verbose? I don't need to provide a value, I just want it to set a variable so that if set my script will do something extra.
Or is there a way that I could use the -Force parameter? Is there some script variable that would be set that I can check if it was used?
Thanks.
Mar 11 2021 03:29 PM
SolutionHello @huntantr,
If I understood you correctlly, you can use Switch parameter type in your script:
Switch parameters are parameters with no parameter value. They're effective only when they're used and have only one effect.
For example you can use something similar to this:
function Do-Magic
{
[CmdletBinding(SupportsShouldProcess=$true)]
[Alias('magic')]
Param
(
[Switch]
$SkipRabbitTrick
)
Begin{}
Process{
if($SkipRabbitTrick){
Write-Verbose "Performance without Rabbit"
}else{
Write-Verbose "Taking Rabbit out of Hat"
}
}
End{}
}
Hope that helps.
Mar 23 2021 09:19 AM