Load variables from another powershell script

后端 未结 3 1361
陌清茗
陌清茗 2020-12-15 02:27

I have several scripts that could be reusing variables so I\'d like to isolate variables in their own Variables.ps1 script, i.e.

$var1 = \"1\"
$var2 = \"2\"
         


        
3条回答
  •  借酒劲吻你
    2020-12-15 03:00

    # var.ps1
    $Global:var1 = "1"
    $Global:var2 = "2"
    

    This works. Whether it's better or worse than "dot sourcing" probably depends on your specific requirements.

    PS > .\var.ps1
    PS > $var1
    1
    PS > $var2
    2
    PS >
    

提交回复
热议问题