Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
.net 我是否可以在导入的模块(如Powershell中的myModule.MyFunction())中调用函数?_.net_Powershell_Module - Fatal编程技术网

.net 我是否可以在导入的模块(如Powershell中的myModule.MyFunction())中调用函数?

.net 我是否可以在导入的模块(如Powershell中的myModule.MyFunction())中调用函数?,.net,powershell,module,.net,Powershell,Module,如果我已将ModuleFo导入到脚本中,其中有一个函数栏() 我是否可以这样调用此函数: moduleFoo.Bar 而不是 Bar 这样,阅读脚本的人就可以理解该条是从哪个模块调用的?您可以给函数名指定如下内容: moduleFoo.Bar # prefixing each function in your module with the module name + . 但这不符合函数或cmdlet的标准powershell命名约定(动词noum) 您还可以创建别名,在函数/cmdlet

如果我已将ModuleFo导入到脚本中,其中有一个函数栏()

我是否可以这样调用此函数:

moduleFoo.Bar
而不是

Bar

这样,阅读脚本的人就可以理解该条是从哪个模块调用的?

您可以给函数名指定如下内容:

moduleFoo.Bar # prefixing each function in your module with the module name + .
但这不符合函数或cmdlet的标准powershell命名约定(动词noum)

您还可以创建别名,在函数/cmdlet前面加上
modulefo.

如果只需要知道函数/cmdlet所属模块的名称,则可以使用:

(gcm bar).Modulename

如果使用-AsCustomObject开关导入模块,则可以将其命名为$modulefo.Bar:

$moduleFoo = Import-Module moduleFoo -AsCustomObject
$moduleFoo.Bar
另一个选项是使用命令全名(module\command)调用它:


这似乎对我不起作用,有什么解释吗<代码>PS>(gcm df).模块名称CoreSmac PS>CoreSmac.df CoreSmac.df:Le terme«CoreSmac.df»不适用于侦察命令、功能、脚本或可裁剪程序的通信名称。Vérifiez l'Orthography du nom,你是一个存在的化学物质,Vérifiez que le chemin d'accès est correct et réessayez。Au-caractère-Ligne:1:1+CoreSmac.df+~~~~~~~~~~~~~~~~~类别信息:ObjectNotFound:(CoreSmac.df:String)[],CommandNotFo undException+FullyQualifiedErrorId:CommandNotFoundException@Kayasax存在误解:
(gcm条).Modulename
返回cmdlet/函数来自的模块的名称。是,我理解,正在运行(gcm df)。Modulename->PS respond CoreSmac。现在我调用CoreSmac.df->CommandNotFound@Christian@Kayasax很抱歉但是我在回答中没有说在
(gcm df).ModuleName
之后,您可以将
df
cmdlet称为
CoreSmac.df
。这就是误解;)哇,在您的回答中,您告诉#在模块中的每个函数前面加上模块名+。CoreSmac是我的模块名,df是我的函数名,所以CoreSmac.df应该可以工作吗?顺便说一句,我不能以@Christian开始我的评论,你知道为什么吗?
PS> moduleFoo\Bar