Multiple ParameterSet Conundrum

Welcome Forums General PowerShell Q&A Multiple ParameterSet Conundrum

Viewing 0 reply threads
  • Author
    Posts
    • #190567
      Participant
      Topics: 3
      Replies: 1
      Points: 7
      Rank: Member

      Hi All,
      I'm writing some basic powershell wrappers around Ciscos AXL SOAP interfaces.  I need to pass two sets of mutually exclusive parameters, and am having issues finding the best way to do that...  Any ideas and suggestions are greatly appreciated!  Issues below:

      1. Authentication is passed by username/password credentials or a "cookie", essentially a Token, that is returned in the header of any successful API call.  The credentials are a pscredential object, and the cookie is a securestring.  One of these is required for authentication
      2. Other parameters are also passed.  I can either pass a UUID to identify the record requested, or several other parameters (user, device, route pattern...).  Again, identically to the authentication, I need to pass one or the other, but not both.

      If it were either one of those, using parameter sets solves the problem very easily.
      If the authentication parameter was the same data type, I could use a single mandatory parameter.  Is there a way to "overload" or allow multiple data types for a single parameter?
      I think I can use ValidateScript to accomplish what I need, but it seems like there may be a more efficient solution.

      Code excerpt of my parameter block below.  Please let me know if there is any further information that would be useful.  Thanks in Advance!

      param (
      # CUCM Uri
      [Parameter(Mandatory=$true)]
      [string]
      $Uri,
      
      # CUCM Version
      [Parameter(Mandatory=$true)]
      [string]
      $CUCMVersion,
      
      # Authentication Method (Either Cookie or Credentials)
      [Parameter()]
      [ValidateSet('Credential','Cookie')]
      [string]
      
      $AuthenticationMethod,
      # Credential with access to CUCM AXL services
      [Parameter(Mandatory=$true, ParameterSetName='Credential')]
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='UUID')]
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      [pscredential]
      $Credential,
      
      # Authentication Cookie
      [Parameter(Mandatory=$true, ParameterSetName='AuthenticationCookie')]
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='UUID')]
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      [string]
      $AuthenticationCookie,
      
      # UUID of Translation Pattern
      [Parameter(Mandatory=$true, ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName='UUID')]
      #[Parameter(Mandatory=$false, ParameterSetName='AuthenticationCookie')]
      #[Parameter(Mandatory=$false, ParameterSetName='Credential')]
      [string]
      $UUID,
      
      # Translation Patter Name
      [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      #[Parameter(Mandatory=$false, ParameterSetName='AuthenticationCookie')]
      #[Parameter(Mandatory=$false, ParameterSetName='Credential')]
      [string]
      $Pattern,
      
      # Route Partition Name
      [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      #[Parameter(Mandatory=$false, ParameterSetName='AuthenticationCookie')]
      #[Parameter(Mandatory=$false, ParameterSetName='Credential')]
      [string]
      $RoutePartitionName,
      
      # Dial Plan Name
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      #[Parameter(Mandatory=$false, ParameterSetName='AuthenticationCookie')]
      #[Parameter(Mandatory=$false, ParameterSetName='Credential')]
      [string]
      $DialPlanName,
      
      # Route Fileter Name
      [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName, ParameterSetName='Pattern')]
      #[Parameter(Mandatory=$false, ParameterSetName='AuthenticationCookie')]
      #[Parameter(Mandatory=$false, ParameterSetName='Credential')]
      [string]
      $RouteFilterName
      )
Viewing 0 reply threads
  • You must be logged in to reply to this topic.