Questions tagged [parameter-sets]

33 questions
1
vote
1 answer

PowerShell ParameterSet Groups

My function has two groups of parameters (A, B), where only one parameter may be used within the group (A1 or A2, B1 or B2), both or only one group may be used. For demonstration I have the following code. Function Test-1{ Param( …
fabian
  • 63
  • 5
1
vote
1 answer

Powershell - Parameter sets

I have a function that have this parameters: param ( [Parameter (Mandatory = $false, ParameterSetName = "SendMail", HelpMessage = "Call this parameter to send information mail ONLY.")] [switch]$SendMail, …
FranciscoNabas
  • 505
  • 3
  • 9
1
vote
2 answers

Postional Binding and ParameterSets

I'm struggling to understand the behavior of parameter sets and positional binding. Here is the sample function. function Test-PositionBinding { [CmdletBinding(DefaultParameterSetName = 'ParamSet2')] param ( …
StephenP
  • 3,895
  • 18
  • 18
1
vote
1 answer

Trouble with multiple parameter sets

I need to get three parameters for a function that I am creating. Parameter one must be in all parameter sets. The other two parameters has multiple permutations. I tried playing around with the parameter sets and I've searched for other threads,…
1
vote
1 answer

PowerShell parameter sets or dynamic parameters

I'm trying to figure out which method would work best for the following situation. Example function: Set-APICredentials { [CmdletBinding()] param( [Parameter(Mandatory)] [string]$APIUser, [Parameter(Mandatory)] …
Bennett
  • 99
  • 9
1
vote
1 answer

Conditional Mandatory in PowerShell

I'm trying to make a parameter mandatory, but only if another parameter uses certain ValidateSet values. It seems that using a code block on Mandatory doesn't work as expected. function Test-Me { [CmdletBinding()] Param ( …
srbrills
  • 1,451
  • 2
  • 13
  • 33
1
vote
1 answer

Parameter sets - how do I make the default work?

I'm writing a function that updates a *.CSV file to be picked-up by a puppet script that will update a DNS Zone. Since I don't want to break the real .CSV file, I've added a dummy-file. While I'm developing this function, I have three parameter…
Daniel
  • 13
  • 3
1
vote
2 answers

Parameters issue in script

Can someone tell what I am doing wrong in the below I wrote: function set-harden { [CmdletBinding(DefaultParameterSetName='NormalHardening')] param ( [Parameter(ParameterSetName='DoNotRemoveFromDomain')] [Parameter(ParameterSetName='PermitHTTP'…
lara400
  • 4,646
  • 13
  • 46
  • 66
0
votes
1 answer

How to set positional parameters in parameter sets?

I wrote a function with four parameters. The first two parameters are mandatory for both sets : Payload and Algorithm. The last two parameters (Secret and FilePath) define the parameter set. The order of defined paramters…
Alex_P
  • 2,580
  • 3
  • 22
  • 37
0
votes
1 answer

Powershell - Multiple Sets of Parameter Sets

Consider these parameters: [parameter(Mandatory = $true)] [string[]]$UserId, [parameter(Mandatory = $true)] [string[]]$EmployeeId, [parameter(Mandatory = $true)] [string[]]$GroupId, …
0
votes
1 answer

Require all parameters, if one of the parameters in a parameterset is set

I want to make all parameters in a parameterset mandatory, but only if one of the parameters is actually specified (all or none situation). So i want to be able to call my function as either Test-Mandatory -Param1 or Test-Mandatory -Param1 -Param2…
DEVries
  • 101
0
votes
1 answer

Powershell "Parameter set cannot be resolved" error when executing script

I have a powershell script with rather long parameter sets: Param( [Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Senders')] [Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Recipients')] …
Luis A.
  • 31
  • 8
0
votes
2 answers

How do set parameter dependencies

Up till now I was more or less avoiding parameter-sets in my PowerShell script as I find them very verbose and quiet difficult to implement for complex dependencies. There are several similar questions and answers at StackOverflow but I can find an…
iRon
  • 20,463
  • 10
  • 53
  • 79
0
votes
1 answer

Powershell, Switch naming ParameterSets

Original Question - Update below - Final code in marked answer More or less a simple question I hope but my brain is fried. I'm trying to write a module to set registry key permissions, named 'Set-RegistryPermissions', and have a slight problem with…
Duzzy
  • 171
  • 1
  • 4
0
votes
1 answer

Passing ParameterSet values to other ParameterSet causes AmbiguousParameterSet exception

I am trying to call a PowerShell function that has a parameter set, using another PowerShell function with a parameter set. In the code below, I want to call Entry-Point using either the -ABC or -DEF switch, not both. However, when I run Entry-Point…
BlueTriangles
  • 1,124
  • 2
  • 13
  • 26