Hi,
I’ve successfully used ParameterSetNames to limit the choices at runtime for scripts and functions, including using multiple parameter sets in the past.
I’m trying to get my head around the following use case:
I’ve written objects in the New-x, Get-x, Remove-x format and now I’m looking at the Update-x function. This object currently takes a name and a label parameter as these are the available properties for this object.
As part of my update, I want to limit the update of the object to an existing object, so I’m using a dynamic parameter (-Name) with a collection of the existing objects to ensure that the user can only update an object that exists.
What I’m trying to do define my parametersets to support the following input parameters:
Update-x -Name "List of available objects in a validateset as dynamicparameter" -NewName 'NewObjectName' Update-x -Name "List of available objects in a validateset as dynamicparameter" -NewLabel 'NewObjectLabel' Update-x -Name "List of available objects in a validateset as dynamicparameter" -NewName 'NewObjectName' -NewLabel 'NewObjectLabel'
Essentially, I want to
always provide an object name, with a newname or
always provide an object name, with a newlabel or
always provide an object name, with a new name and a new label
I can’t keep them all in the same parameter set and then force with Mandatory = $true because if I run:
update-x -Name ‘SomeName’ -NewName ‘SomeNewName’
that will force me to provide a new label when I want to keep the existing label in place.
When I use ParameterSet and cover my multiple parameter sets, because newname and newlabel can be updated, there seems to be no way to distinguish if I just provide a newname or a newlabel.
Is there a way around this that I’m missing?
I’m aware I could validate within my function, but this object is a base object for multiple objects which will have much more properties to update, so I’m trying to handle this with parameter sets rather than in-function validation as I think that scales better.
Thanks for any assistance