title: Functions from an imported module are not available in a powershell script
body: <p>I am working with PowerShell V 4.0 on a Windows Server machine. I have encountered a problem that I am not able to debug or find a solution. </p>
  
  <p>I have a ps1 script that imports two psm1 modules A and B. (B in turn imports another module C). </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I am not able to use the functions from the second module moduleB in the script. When I run the script, it throws errors where ever a function from the module B is used. The error is below (get-hostLocalCred is the function name.) </p>
  
  <pre><code>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.
  </code></pre>
  
  <p>The following is the content in the moduleB. </p>
  
  <pre><code>#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
  }
  .
  .
  .
  .
  </code></pre>
  
  <p>The functions from moduleA are being executed properly, but I am not able to execute the function from moduleB. 
  Also, After running the script in the console, When I try to lookup the functions available in the Module B, using the following commandlet, </p>
  
  <pre><code>Get-Command -Module ModuleB
  </code></pre>
  
  <p>I only see the functions defined in the ModuleC, which is imported by moduleB, but I donot see any of the functions defined in the moduleB. I have been working with powershell but this is the first time I have seen this issue. </p>
  
  <p>When I do a Get-Module, I see only moduleA and moduleB. </p>
  
  <p>All the Modules are imported in the following way: </p>
  
  <pre><code>Import-Module  $PSScriptRoot/../lib/newmodules/moduleB.psm1 
  </code></pre>
  
  <p>Importing modules Globally has also not solved the problem. </p>
  
  <p>Importing modules by giving actual path like following has also not solved the issue.</p>
  
  <pre><code>Import-Module C:\folderpath\ModuleB.psm1 
  </code></pre>
  
  <p>All the functions in all the modules have been defined as following. There is no difference in the function definition in any of the modules. </p>
  
  <pre><code>function get-hostLocalCred {
      Param($xmldata)
      # Function Definition 
      return $result
  }
  </code></pre>
  
  <p>I might be missing a simple thing but I am not able to get it. I have been importing modules normally and working with them since long time but this is the first time I ran into this issue. Thanks in advance for the help. </p>