Passing multiple values to a single PowerShell script parameter

后端 未结 4 1784
长发绾君心
长发绾君心 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:23

    I call a scheduled script who must connect to a list of Server this way:

    Powershell.exe -File "YourScriptPath" "Par1,Par2,Par3"
    

    Then inside the script:

    param($list_of_servers)
    ...
    Connect-Viserver $list_of_servers.split(",")
    

    The split operator returns an array of string

提交回复
热议问题