Import Variables from Text File in Powershell

前端 未结 1 896
孤城傲影
孤城傲影 2021-01-12 13:39

I\'ve got a couple of Powershell scripts that automate DLL transferal and I\'d like to import the variables from one text file into the various scripts. My example:

相关标签:
1条回答
  • 2021-01-12 14:29

    This can be accomplished by Dot Sourcing.

    Create a .ps1 file, declare your variables in it, then dot source the file. This will bring any variables declared in the file into the global scope.

    Example:

    Contents of Variables.ps1:

    $foo = "blarg"
    $bar = "other blarg"
    

    Dot source it:

    . ./Variables.ps1
    Write-Host "$foo $bar"
    
    0 讨论(0)
提交回复
热议问题