Powershell编辑变量值

时间:2015-11-17 10:49:27

标签: powershell

我有一个powershell文件,其中有一个名为$CurrentReleaseNumber的变量:

$CurrentReleaseNumber="4.5"

我想要做的是在另一个PowerShell文件中编辑此变量的值。第二个PowerShell文件将更新此变量的值,新值现在应该反映在第一个powershell文件中。 因此,在执行第二个PowerShell文件后,第一个powershell文件应如下所示:

$CurrentReleaseNumber="4.7"

1 个答案:

答案 0 :(得分:1)

你可以尝试这个,它被称为 dot-sourcing (假设两个文件都在同一个文件夹中,你使用的是PS版本3或更高版本):

script1.ps1:

$myVariable = "hey !"

script2.ps1:

. "$PSScriptRoot\script1.ps1"

$myVariable

输出

hey !