Import-Module with -force removes imported module function?

限于喜欢 提交于 2021-02-19 03:38:04

问题


I have "ModuleA" that imports functions from modules "ADAutoDeployUtilities" and "Common_LoggingNotifications" using the code below. However, I keep receiving the exception (listed below) when I try to import Common_LoggingNotifications using -force. If I do not load Common_LoggingNotifications, only the ADAutoDeployUtilities functions are imported (which doesn't include writeJobLog) and everything runs fine, although I get the indicated exception when running on the server. I have also provided a screenshot of the output using -verbose. Two things I don't understand from the screenshot; any thoughts?

  1. Why does "writeJobLog" get removed when I import ADAutoDeployUtilities (writeJobLog doesn't belong to that module)?
  2. Why is "writeJobLog" not recognized, as it is clearly being imported when Common_LoggingNotifications is imported?

In "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"

Screenshot after running "ModuleA"...

来源:https://stackoverflow.com/questions/40005664/import-module-with-force-removes-imported-module-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!