title: Why is Powershell not able to find my imported command after the first time the script is executed?
body: <p>I have two Powershell scripts. Script A contains a simple Powershell function. Script B imports script A and then calls the function defined in script A. This works fine the first time script B is executed but on subsequent executions Powershell complains the the function defined in script A cannot be found. Adding -Force to the import-module call in script B seems to solve the problem but I'd like to understand why Powershell exhibits this unexpected behavior.</p>
  
  <p>Here is script A.</p>
  
  <pre><code>function foo($param)
  {
      Write-Host $param
  }
  </code></pre>
  
  <p>Here is script B</p>
  
  <pre><code>Import-Module "C:\SomePath\scriptA.ps1"
  
  Foo "hello"
  </code></pre>
  
  <p>I am calling the script from the PS command line:</p>
  
  <pre><code>.\scriptB.ps1
  </code></pre>
  
  <p>Here is the error I get the second and subsequent time that the script is executed.</p>
  
  <p><a href="https://i.stack.imgur.com/NWKCG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NWKCG.png" alt="enter image description here"></a></p>