Multiple Strings

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

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
   }

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

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