Powershell脚本中无法使用来自导入模块的功能

用户名

我正在Windows Server计算机上使用PowerShell V 4.0。我遇到了无法调试或找到解决方案的问题。

我有一个ps1脚本,可以导入两个psm1模块A和B。(B又可以导入另一个模块C)。

Import-Module  $PSScriptRoot\..\lib\infra\moduleA.psm1 
Import-Module  $PSScriptRoot\..\lib\nwm\moduleB.psm1 

#get-logger function works fine. This is defined in moduleA
$log = get-logger

$smisXmlData = [xml] $smisConfigData

#The function get-hostLocalCred is defined in moduleB. This is where the error occurs. 
($username, $password) = get-hostLocalCred $smisXmlData

我无法使用脚本中第二个模块moduleB的功能。当我运行脚本时,在使用模块B中的函数的地方都会引发错误。错误如下(get-hostLocalCred是函数名称。)

get-hostLocalCred : The term 'get-hostLocalCred' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling  of the name, or if a path was included, verify that the path is correct and try again.

以下是moduleB中的内容。

#Importing moduleC. 
Import-Module  $PSScriptRoot/../infra/moduleC.psm1

#Defining required functions. These are the functions that are not available in the above script. 
function get-hostLocalCred {
    Param($xmldata)
    $log.entry()
    $username = $xmldata.component.yourhost.localcred.username
    $log.debug("USERNAME: $username")
    $password = $xmldata.component.yourhost.localcred.password
    $log.exit()
    return $username, $password
}

function new-ArrayCredObj {
Param([Parameter(Mandatory = $true)] $user,
  [Parameter(Mandatory = $true)] $password)
    $log.entry()
    $log.info("Creating custom Object")
    $log.debug("User : $user")
    $log.debug("Pwd : $password")
    $arrayCred = New-Object psobject
    $arrayCred | Add-Member -MemberType NoteProperty -Name auser -Value $user
    $arrayCred | Add-Member -MemberType NoteProperty -Name password -Value $password
    $log.exit()
    return $arrayCred
}
.
.
.
.

来自模块A的功能正在正确执行,但是我无法从模块B执行功能。另外,在控制台中运行脚本后,当我尝试使用以下命令行开关查找模块B中可用的功能时,

Get-Command -Module ModuleB

我只看到在ModuleC中定义的功能,该功能是由moduleB导入的,但是看不到moduleB中定义的任何功能。我一直在使用Powershell,但这是我第一次看到此问题。

当我执行Get-Module时,只能看到moduleA和moduleB。

所有模块都是通过以下方式导入的:

Import-Module  $PSScriptRoot/../lib/newmodules/moduleB.psm1 

全局导入模块也没有解决问题。

通过提供如下所示的实际路径导入模块也无法解决问题。

Import-Module C:\folderpath\ModuleB.psm1 

所有模块中的所有功能已定义如下。在任何模块中,功能定义都没有区别。

function get-hostLocalCred {
    Param($xmldata)
    # Function Definition 
    return $result
}

我可能错过了一件简单的事情,但我无法做到。很长时间以来,我一直在正常导入模块并使用它们,但这是我第一次遇到此问题。在此先感谢您的帮助。

贾斯汀

当您的清单(.psd1)没有指定根模块时,会发生此问题。

@{

# Script module or binary module file associated with this manifest.
RootModule = 'mymodule.psm1' 
...

以前,从New-ModuleManifest生成它时,默认情况下它会被注释掉

@{

# Script module or binary module file associated with this manifest.
# RootModule = '' 
...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Powershell脚本中无法使用来自导入模块的功能

来自分类Dev

如何在本地函数中使用来自导入模块的函数?

来自分类Dev

无法识别来自导入模块的变量

来自分类Dev

无法使用来自不同Maven模块的类

来自分类Dev

导入脚本中的功能无法执行

来自分类Dev

使用来自另一个Powershell脚本的参数调用PowerShell脚本

来自分类Dev

使用 powershell,如果安装 Server-Media-Foundation 功能,则无法导入 ADDSDeployment 模块

来自分类Dev

Powershell脚本使用来自.txt或.csv的输入在第二个.csv文件中查找值

来自分类Dev

Powershell不从模块导入功能

来自分类Dev

无法使用来自Future函数中参数的数据

来自分类Dev

来自导入的 Objc 头文件中的 #define 的未解析标识符

来自分类Dev

无法使用来自node_modules的打字稿导入react-tap-event-plugin

来自分类Dev

使用来自 easy-rsa 的证书签署 Powershell 脚本

来自分类Dev

Nodemon无法在Docker上使用来自package.json的npm脚本

来自分类Dev

在Windows Server 2008中:Powershell无法导入模块ActiveDirectory

来自分类Dev

在Python中,如何从该脚本导入的模块中调用脚本功能?

来自分类Dev

逐行迭代来自导入的数据帧的向量

来自分类Dev

GWT:如何使用来自单独模块的bean?

来自分类Dev

使用来自定制CDN源的定制模块的Dojo

来自分类Dev

NodeJS使用来自不同文件的模块

来自分类Dev

使用来自多个模块的回调函数

来自分类Dev

列表中的模块无法导入

来自分类Dev

无法使用动态导入的模块

来自分类Dev

无法修改源自导入文件的评估对象

来自分类Dev

使用来自VBscript的参数调用Python脚本

来自分类Dev

在 python 脚本中使用来自 Ajax 的数据

来自分类Dev

使用来自 tcl 的参数调用 python 脚本

来自分类Dev

在脚本中使用来自链接游戏对象的组件

来自分类Dev

无法使用来自API的数据在UITableView中插入单元格

Related 相关文章

  1. 1

    Powershell脚本中无法使用来自导入模块的功能

  2. 2

    如何在本地函数中使用来自导入模块的函数?

  3. 3

    无法识别来自导入模块的变量

  4. 4

    无法使用来自不同Maven模块的类

  5. 5

    导入脚本中的功能无法执行

  6. 6

    使用来自另一个Powershell脚本的参数调用PowerShell脚本

  7. 7

    使用 powershell,如果安装 Server-Media-Foundation 功能,则无法导入 ADDSDeployment 模块

  8. 8

    Powershell脚本使用来自.txt或.csv的输入在第二个.csv文件中查找值

  9. 9

    Powershell不从模块导入功能

  10. 10

    无法使用来自Future函数中参数的数据

  11. 11

    来自导入的 Objc 头文件中的 #define 的未解析标识符

  12. 12

    无法使用来自node_modules的打字稿导入react-tap-event-plugin

  13. 13

    使用来自 easy-rsa 的证书签署 Powershell 脚本

  14. 14

    Nodemon无法在Docker上使用来自package.json的npm脚本

  15. 15

    在Windows Server 2008中:Powershell无法导入模块ActiveDirectory

  16. 16

    在Python中,如何从该脚本导入的模块中调用脚本功能?

  17. 17

    逐行迭代来自导入的数据帧的向量

  18. 18

    GWT:如何使用来自单独模块的bean?

  19. 19

    使用来自定制CDN源的定制模块的Dojo

  20. 20

    NodeJS使用来自不同文件的模块

  21. 21

    使用来自多个模块的回调函数

  22. 22

    列表中的模块无法导入

  23. 23

    无法使用动态导入的模块

  24. 24

    无法修改源自导入文件的评估对象

  25. 25

    使用来自VBscript的参数调用Python脚本

  26. 26

    在 python 脚本中使用来自 Ajax 的数据

  27. 27

    使用来自 tcl 的参数调用 python 脚本

  28. 28

    在脚本中使用来自链接游戏对象的组件

  29. 29

    无法使用来自API的数据在UITableView中插入单元格

热门标签

归档