Questions tagged [parameter-sets]
33 questions
7
votes
1 answer
Is there some way to define a parameterless powershell parameter set?
I've got some fairly complex functions that I'm writing for a library module, with lots of different ways it can be called. However, it is in fact possible to default all of them, but when I try to call my function with no parameters the call fails…

bwerks
- 8,651
- 14
- 68
- 100
6
votes
1 answer
Can a PowerShell function handle multiple input types?
I'm working on a function that compares two objects so it detects them if they are identical. However I would like it to also work with other types like strings or integers.
C++ lets you declare different functions with the same name to handle…

rovda
- 221
- 2
- 10
5
votes
1 answer
Powershell parameter sets and optional parameters
I'm writing a function for which two parameters should be exclusive and optional.
Here are valid inputs:
new-event -Title sometitle -Text sometext -TimestampHappened 1234567 -SomeOtherOptionalParam somestring
new-event -Title sometitle -Text…

simsaull
- 319
- 1
- 4
- 12
4
votes
2 answers
ParameterSetName detection in PowerShell functions matching on ValueFromPipeline input object type?
I'm seeing some strange behavior in a custom function I've written, and so I wrote some quick test functions with different characteristics to exhibit these behaviors. The problem arises when parameter sets are similar enough that the only…

bwerks
- 8,651
- 14
- 68
- 100
4
votes
1 answer
PowerShell unable the determine which Parameter Set is in use
I have a function with four parameters, two of which can either be set or not. I'm trying to use Parameter Sets to identify which parameters have been set, but I'm hitting some issues with Parameter Set resolution. These are the four possible…

David Gard
- 11,225
- 36
- 115
- 227
3
votes
1 answer
Why can't parameter sets be resolved based on [string] vs [hashtable] vs [pscustomobject]?
Consider this function:
function Test-Discrimination
{
[CmdletBinding()]
param
(
[parameter(ValueFromPipeline = $true,
Mandatory = $true,
ParameterSetName = 'string')]
[string]
…

alx9r
- 3,675
- 4
- 26
- 55
3
votes
1 answer
Powershell defaultparameterset not working. error
I am trying to use parameter set and use default parameter set. But the default parameter set doesn't seem to work for me. Any help is much appreciated. I can easily use validate set with default action but I want to know what I am doing wrong…

tarunmunjal
- 33
- 1
- 3
2
votes
1 answer
How to support multiple, mutually exclusive parameters?
I must write a script to get instances of Thing.
Each Thing contains an event timestamp.
I need to allow the user to specify a timestamp range.
There are four (4) time-specifying parameters
None are mandatory
$Since and $StartTimestamp are mutually…

lit
- 14,456
- 10
- 65
- 119
2
votes
3 answers
"Parameter set cannot be resolved" when piping a parameter with specific combinations of other parameters
I have written a function which uses four parameters, and four parameter sets. The first parameter, $Path, is unassigned to a set, and therefore belongs to all sets. It is also mandatory, and the only parameter that can be passed from the pipeline.…

Alex
- 23
- 6
2
votes
1 answer
Powershell one of two parameters are mandatory
I wrote a powershell script with some parameters but I can't figured out how to get the syntax like
script.ps1 [A|B] C [D]
script.ps1 [A|B] C E F
script.ps1 [A|B] C G
Target:
A or B or both are passed
C is always mandatory
if no other parameter is…

Citu
- 21
- 5
2
votes
2 answers
How do you change a parameter's throw message?
Question:
Looking to either change the error message displayed to say they need the '-passed, -warning, or -failed' to be included with the cmdlet parameters or to not care if the three are missing and to write the message (assuming its there).…

Treasure Dev
- 560
- 4
- 8
2
votes
1 answer
How do you hide a PowerShell parameter set?
Say you have and old, deprecated parameter set, and a new parameter set:
SYNTAX
Get-FooBar -SomeCommonParameter -NewParameter
Get-FooBar -SomeCommonParameter -OldParameter
I want both…

Mark Raymond
- 906
- 8
- 22
2
votes
2 answers
Parameters - Requiring Some But Not Others - Correct Use of Parameter Sets
So I'm experimenting with PowerShell and having a little trouble understanding parameters. From what I've read if I specify a parameter to be at the same position as another but place it in a separate ParameterSet PowerShell will only require one of…
user4832990
2
votes
2 answers
PowerShell - Can I make a parameter set depend on the value of another parameter?
Let's say I have a function like:
function Authenticate
{
param
(
[ValidateSet('WindowsAuthentication','UsernameAndPassword')]
[string]$AuthenticationType,
[Parameter(ParameterSetName='ParamSet1')]
…

cogumel0
- 2,430
- 5
- 29
- 45
1
vote
1 answer
PowerShell Parameter Set Requires Named Parameter
I have the following snippet of a functions parameters and their sets
function Test {
[CmdletBinding(DefaultParameterSetName='StringConsole')]
param (
[Parameter(Mandatory,
ValueFromPipelineByPropertyName,
…

Martin
- 503
- 1
- 6
- 20