English 中文(简体)
权力hell:如何将主稿中界定的一些参数暴露在所有单元中,这些单元将被称作“主要文字”。
原标题:powershell: how to expose some parameters defined in the main script to all the modules to be called

主要的打字稿界定了3个参数,我像所有模块一样可以使用这些参数,一种办法是使用全球文字,但看坏。

我希望我们能够利用诸如以下这样的东西来通过参数,但不要工作。

  import-module "$currentPathETLLib.psm1" $a $b $c 

我的主要文字如下:

$a  
$b  
$c  
import-module "$currentPathETLLib.psm1" $a $b $c  
import-module "$currentPath图表1"  $a $b $c  

ETLLib.psm1

param($a $b $c)

图表1

param($a $b $c)
问题回答

应使用<代码>ArgumentList参数>。

测试1:

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

进口:<条码>。

Import-Module Test -ArgumentList arg1, arg2, arg3

产出:

arg1
arg2
arg3




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签