title: Run Powershell.exe from command line (cmd.exe) with -Command and -File switches?
body: <p>I have a simple module called <code>MyModule.psm1</code> defined as </p>
  
  <pre><code>function Show-Text($p)
  {
      Write-Host $p
  }
  
  Export-ModuleMember Show-Text
  </code></pre>
  
  <p>Module is saved here -  (<em>All works fine, the normal way via ISE or direct Powershell command line</em>)</p>
  
  <pre><code>C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\MyModule (because 64-bit OS)
  </code></pre>
  
  <p>Now, I have a script called <code>Test.ps1</code> like this</p>
  
  <pre><code>Show-Text "Hello World"
  </code></pre>
  
  <p><strong>NB: I do not want to do Import-Module MyModule in the ps1 file</strong></p>
  
  <p>I am running following command from a cmd.exe window</p>
  
  <pre><code>C:\&gt;Powershell -Command "&amp; {Import-Module MyModule}" -File "C:\temp\Test.ps1"
  </code></pre>
  
  <p>I get the following error</p>
  
  <blockquote>
    <p>Import-Module : The specified module 'MyModule' was not loaded because
    no valid  module file was found in any module directory. At line:1
    char:17
    + &amp; {Import-Module &lt;&lt;&lt;&lt;  MyModule} -File Show.ps1
        + CategoryInfo          : ResourceUnavailable: (MyModule:String) [Import-M    odule], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm<br>
    ands.ImportModuleCommand</p>
  </blockquote>
  
  <p><em>Can somebody help me how to execute <code>exactly what I have stated</code> above via <strong>cmd.exe ONLY</strong> without hard-coding or specifying the full Module Path please ?</em></p>
  
  <p>Something on the similar lines we do for loading SystemModules - <code>powershell.exe -ImportSystemModules</code></p>