Passing multiple values to a single PowerShell script parameter

后端 未结 4 1797
长发绾君心
长发绾君心 2020-12-04 14:52

I have a script to which I pass server name(s) in $args.

This way I can do stuff to this (these) server(s) using foreach:

.\\script.ps1          


        
4条回答
  •  情书的邮戳
    2020-12-04 15:25

    One way to do it would be like this:

     param(
           [Parameter(Position=0)][String]$Vlan,
           [Parameter(ValueFromRemainingArguments=$true)][String[]]$Hosts
        ) ...
    

    This would allow multiple hosts to be entered with spaces.

提交回复
热议问题