I am having some scope issues when powershell scripts are for point sources. Suppose I have one script 'A.ps1':
$VERSION = "1.0"
And script B.ps1
$VERSION = "2.0" function Write-Version { Write-Host "B.ps1 version $VERSION" } Write-Version
The result of A.ps1 will be:
B.ps1 version 2.0 A.ps1 version 2.0
Why this happens is obvious. The $VERSION variable from B.ps1 is placed in A.ps1 and overwrites this variable. In fact, this also happens with Write-Version , but here A.ps1 overwrites the B-version, but since Write-Version is called in B.ps1 before this happens, we can still see the output of the B Write-Version function .
The question, of course, is how to prevent this? I tried various options for features, but this doesn't seem to work when dot-sourcing. And since B.ps1 has the functions that I need in area A, just calling B.ps1 is probably not an option.
Does anyone have any ideas?
source share