2011-01-31 20 views
2

主調用腳本定義了3個參數,我想所有的模塊都可以使用它們,一種方法是使用全局腳本,但看起來不好。powershell:如何將主腳本中定義的一些參數公開給所有要調用的模塊

我希望我們可以使用類似下面的傳遞參數,但不起作用

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

我的主要腳本是這樣的:

$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) 

回答

7

應該使用ArgumentList參數Import-Module

Test.psm1:

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

使用ArgumentList導入:

Import-Module Test -ArgumentList arg1, arg2, arg3 

輸出:

arg1 
arg2 
arg3 
相關問題