When writing advanced functions with two (or more) parameter sets, sometimes you need to use conditional logic based on what parameter set is in use. This can be achieved easily by using the built-in PSCmdlet variable.
if ($PSCmdlet.ParameterSetName -eq 'ParameterSet1') { Write-Host 'You are using the "ParameterSet1" parameter set' } else { Write-Host 'You are using the "ParameterSet2" parameter set' }
This code snippet shows you how to use the ParameterSetName property of the PSCmdlet variable (which is actually an object of type System.Management.Automation.PSCmdlet) to check what parameter set is in use. In this example I have two parameter sets, named ‘ParameterSet1’ and ‘ParameterSet2’.