If a parameter is not an array show a different parameter.

Welcome Forums General PowerShell Q&A If a parameter is not an array show a different parameter.

Viewing 5 reply threads
  • Author
    Posts
    • #209724
      Participant
      Topics: 17
      Replies: 47
      Points: 134
      Rank: Participant

      Hey guys, I want to accept a string array or not, but if it is an array that is inputted then i want to allow another parameter (set).

      Basically, if someone inputs an array of folders then i don’t want to allow an recursive switch, but if they provide a single path then i do want to allow recursive.

      param (
              [parameter(Mandatory = $true, ValueFromPipeline = $True)]
              [String[]]$FolderPath,
              [Switch]$Recursive
          )
    • #209748
      Participant
      Topics: 6
      Replies: 93
      Points: 427
      Helping Hand
      Rank: Contributor

      $FolderPath.Count

       

    • #209751
      Participant
      Topics: 17
      Replies: 47
      Points: 134
      Rank: Participant

      Unless I am missing something that won’t ‘hide’ the -recursive switch if $FolderPath.Count -gt 1..

      I’m wanting to hide that switch like when you use ParameterSets.

       

      (or it just may not be possible)

      • This reply was modified 2 months, 2 weeks ago by Gary.
    • #209763
      Participant
      Topics: 17
      Replies: 47
      Points: 134
      Rank: Participant

      Never mind. I decided to just allow it for both.

    • #209991
      Participant
      Topics: 6
      Replies: 93
      Points: 427
      Helping Hand
      Rank: Contributor

      I was simply trying to point out your logic might be based on that property. The rest of your intent was unclear to me, sorry. The way I understood the question was determine if multiple entries and branch accordingly. In that same logic, you could also determine to use the Recursive switch or not.

    • #210021
      Moderator
      Topics: 3
      Replies: 216
      Points: 1,176
      Helping Hand
      Rank: Community Hero

      Hi Gary,

      Please refer to Dynamic Parameters and ArgumentCompleter, you will get some idea about how to handle this scenario.

      Thank you.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.