Starting .ps1 Script from PowerShell with Parameters and Credentials and getting output using variable

前端 未结 4 1839
无人共我
无人共我 2020-12-19 01:58

Hello Stack Community :)

I have a simple goal. I\'d like to start some PowerShell Script from an another Powershell Script, but there are 3 conditions:

    <
4条回答
  •  被撕碎了的回忆
    2020-12-19 02:37

    What you can do it the following to pass a parameter to a ps1 script.

    The first script can be a origin.ps1 where we write:

    & C:\scripts\dest.ps1 Pa$$w0rd parameter_a parameter_n
    

    Th destination script dest.ps1 can have the following code to capture the variables

    $var0 = $args[0]
    $var1 = $args[1]
    $var2 = $args[2]
    Write-Host "my args",$var0,",",$var1,",",$var2
    

    And the result will be

    my args Pa$$w0rd, parameter_a, parameter_n
    

提交回复
热议问题