tatushar3
tatushar3

Reputation: 111

Powershell edit a variable value

I have a powershell file in which i have a variable named $CurrentReleaseNumber :

$CurrentReleaseNumber="4.5"

What i want to do is edit the value of this variable inside another powershell file. This second powershell file will update the value of this variable and the new value should now reflect in first powershell file. So after execution of second powershell file the first powershell file should look like :

$CurrentReleaseNumber="4.7"

Upvotes: 0

Views: 1586

Answers (1)

sodawillow
sodawillow

Reputation: 13176

You can try this, it is called dot-sourcing (assuming both files are in the same folder and you are using PS version 3 or higher) :

script1.ps1 :

$myVariable = "hey !"

script2.ps1 :

. "$PSScriptRoot\script1.ps1"

$myVariable

Output :

hey !

Upvotes: 1

Related Questions