gpt4 book ai didi

powershell:如何将主脚本中定义的一些参数暴露给所有要调用的模块

转载 作者:行者123 更新时间:2023-12-02 07:48:56 25 4
gpt4 key购买 nike

主要的调用脚本定义了3个参数,我希望所有的模块都可以使用它们,一种方法是使用全局脚本,但看起来很糟糕。

我希望我们可以使用像下面这样的东西来传递参数,但是不起作用

  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)

转换.psm1

param($a $b $c)

最佳答案

应该使用Import-ModuleArgumentList参数。

测试.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

关于powershell:如何将主脚本中定义的一些参数暴露给所有要调用的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4847026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com