Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用PSModuleInfo::invoke(…)方法_Powershell - Fatal编程技术网

Powershell 使用PSModuleInfo::invoke(…)方法

Powershell 使用PSModuleInfo::invoke(…)方法,powershell,Powershell,我无法通过invoke(PSModuleInfo::invoke(…)向模块中定义的函数传递参数。更具体地说,我需要将哈希表作为单个参数传递 下面的代码示例工作意味着正在调用模块中的函数。然而,这一论点没有通过 在模块中: function MyFunc($arg) { .... } 在客户端: $m = Get-Module $name $table = @{1 = 1; 2 = 2 } $m.Invoke( {MyFunc}, @($table) ) # param is

我无法通过invoke(PSModuleInfo::invoke(…)向模块中定义的函数传递参数。更具体地说,我需要将哈希表作为单个参数传递

下面的代码示例工作意味着正在调用模块中的函数。然而,这一论点没有通过

在模块中:

function MyFunc($arg)
{
     ....
}
在客户端:

$m =  Get-Module $name

$table = @{1 = 1; 2 = 2 }

$m.Invoke( {MyFunc}, @($table) ) # param is not passed
$m.Invoke( {MyFunc}, $table ) # param is not passed
$m.Invoke(  MyFunc,  $table ) # param is not passed

# Trying with scalar value
$x = 10
$m.Invoke( {MyFunc}, @($x) ) # param is not passed
$m.Invoke( {MyFunc}, $x ) # param is not passed
$m.Invoke(  MyFunc,  $x ) # param is not passed
$m.Invoke( {MyFunc}, 10 ) # This WORKS, 10 is assigned to $arg in a function
根据我的理解,根据:
,调用的第一个调用应该是正确的语法

$m.Invoke({param($param)MyFunc$param},$x)
谢谢你!这很有效。