Powershell 使用PSModuleInfo::invoke(…)方法
我无法通过invoke(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
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)
谢谢你!这很有效。