带-force的Import-Module删除导入的模块功能?

时间:2016-10-12 18:17:15

标签: powershell windows-7 powershell-v2.0

我有" ModuleA"从模块中导入函数" ADAutoDeployUtilities"和#34; Common_LoggingNotifications"使用下面的代码。但是,当我尝试使用-force导入Common_LoggingNotifications时,我一直收到异常(如下所列)。如果我加载Common_LoggingNotifications,则只导入ADAutoDeployUtilities函数(它不包含writeJobLog)并且一切运行正常,但在服务器上运行时我得到指示的异常。我还使用-verbose提供了输出的屏幕截图。我从屏幕截图中无法理解的两件事情;有什么想法吗?

  1. 为什么" writeJobLog"导入时删除 ADAutoDeployUtilities(writeJobLog不属于该模块)?
  2. 为什么" writeJobLog"不承认,因为它 当Common_LoggingNotifications为时,显然正在导入 输入?
  3. 在" ModuleA" ...

        # Load Module Dependencies
           $ModulesPath = $PreCompareInfoObject.ModulesPath # "c:\modules" for example
           $ModulesList = "ADAutoDeployUtilities,Common_LoggingNotifications"
           $ModulesList.Split(",") | foreach { 
              if (-not (get-module $ModulesPath$_)) { 
                 #import-module $ModulesPath$_ -ErrorAction SilentlyContinue 
                 import-module $ModulesPath$_ -force -verbose
              }
           }
    
    # writeJobLog below throws error: The term 'writeJobLog' 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
    writeJobLog "xxxxx"
    

    运行" ModuleA" ...

    后的屏幕截图

    enter image description here

0 个答案:

没有答案