开发者

powershell: how to expose some parameters defined in the main script to all the modules to be called

开发者 https://www.devze.com 2023-02-07 19:50 出处:网络
Th开发者_运维百科e main calling script defines 3 parameters, and I\'d like all the module can use them, one way is to use global script, but looks bad.

Th开发者_运维百科e main calling script defines 3 parameters, and I'd like all the module can use them, one way is to use global script, but looks bad.

I hope we can use something like the following to pass the parameters, but doesn't work

  import-module "$currentPath\ETLLib.psm1" $a $b $c 

my main script is like:

$a  
$b  
$c  
import-module "$currentPath\ETLLib.psm1" $a $b $c  
import-module "$currentPath\Tranform.psm1"  $a $b $c  

ETLLib.psm1

param($a $b $c)

Tranform.psm1

param($a $b $c)


The ArgumentList parameter of Import-Module should be used.

Test.psm1:

param($a, $b, $c)
Write-Host $a
Write-Host $b
Write-Host $c

Import using ArgumentList:

Import-Module Test -ArgumentList arg1, arg2, arg3

Output:

arg1
arg2
arg3
0

精彩评论

暂无评论...
验证码 换一张
取 消