Multiple Strings

Welcome Forums General PowerShell Q&A Multiple Strings

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #124265

    Participant
    Points: 12
    Rank: Member

    Folks below is the code im working with

    param (
    [Parameter(Mandatory=$true)][string]$server
    )
    $url1="https:/me.me.com/Vapp/5.0/api/OSI?assetName="
    $url2="/OSI.DiscoveryDetails/OSI.SoftwareInstance/SoftwareInstance.Middleware/Middleware.Contact?contactType=PRIMARYRESOLVER/OSI.SoftwareInstance?ColumnSelect=username;,OSI.DiscoveryDetails?ColumnSelect=olaKeonDomain,SoftwareInstance.Middleware?ColumnSelect=installPath,Middleware.Contact?ColumnSelect=qname,OSI?ColumnSelect=environment&format=json"
    $verumqry = $url1 + $server + $url2

    Start-Process -FilePath "iexplore.exe" -ArgumentList $verumqry

     

    Currently i can run the script as test.ps1 server1

    I  need to be able to pass multiple servers from the command line: eg

    test.ps1 server1 server2 server3   ..

    Any help will be greatly appreciated

  • #124277

    Participant
    Points: 110
    Helping Hand
    Rank: Participant

    You would need to allow your parameter to accept multiple values, and add a foreach loop. The below code should do the trick (it is untested)

    param (
     [Parameter(Mandatory=$true)][string[]]$server
     )
     $url1="https:/me.me.com/Vapp/5.0/api/OSI?assetName="
     $url2="/OSI.DiscoveryDetails/OSI.SoftwareInstance/SoftwareInstance.Middleware/Middleware.Contact?contactType=PRIMARYRESOLVER/OSI.SoftwareInstance?ColumnSelect=username;,OSI.DiscoveryDetails?ColumnSelect=olaKeonDomain,SoftwareInstance.Middleware?ColumnSelect=installPath,Middleware.Contact?ColumnSelect=qname,OSI?ColumnSelect=environment&format=json"
     foreach($s in $server)
       {
         $verumqry = $url1 + $s + $url2
         Start-Process -FilePath "iexplore.exe" -ArgumentList $verumqry
       }
    
  • #124334
    js

    Participant
    Points: 318
    Helping Hand
    Rank: Contributor

    The other option is to have a process block, and allow the parameter to be piped in. Then it will automatically process a list.

  • #124433

    Participant
    Points: 290
    Helping Hand
    Rank: Contributor

    You can combine both approaches and have it work either way, as well:

You must be logged in to reply to this topic.