title: How to install a powershell module manually from a powershell script
body: <p>I have a PowerShell Module in <code>powowshell.psm1</code> which I want to install and have immediately available as the alias <code>pow</code>. My <code>install.ps1</code> copies the file to the correct folder, does <code>Import-Module -name PowowShell -Global -Alias pow</code> and then checks to see the command exists via alias with <code>Get-Command "pow"</code> which returns the command.</p>
  
  <p>The problem is, as soon as <code>install.ps1</code> terminates the module is only available via the full name <code>Invoke-PowowShell</code> and not via the alas <code>pow</code>.</p>
  
  <p>If I run the exact same <code>Import-Module</code> code afterwards, with or without <code>-Alias</code> I suddenly have <code>pow</code>.</p>
  
  <p>Why is my module not immediately available as <code>pow</code> but only as <code>Invoke-PowowShell</code>.</p>
  
  <p>Restarting PowerShell does not help.</p>
  
  <p><strong>powowshell.psm1</strong></p>
  
  <pre class="lang-bsh prettyprint-override"><code>function Invoke-PowowShell {
      [CmdletBinding(SupportsShouldProcess)]
      [Alias('pow')]
      #...code here...
      "You have the POWer!"
  }
  Export-ModuleMember -Function Invoke-PowowShell -Alias pow
  </code></pre>
  
  <p><strong>install.ps1</strong>:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>    # Copy .psm1 to correct modules folder /PowowShell/PowowShell.psm1
      # ...
      # Install module globally
      Write-Verbose "Import-Module -name PowowShell -Global -Alias pow"
      Import-Module -name PowowShell -Global -Alias pow
      # Check we have the "pow" alias available
      write-verbose 'Get-Command "pow"'
      $PowowShell = Get-Command "pow"
      write-verbose "`$PowowShell=$PowowShell"
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>Installing PowowShell module to C:\Users\me\Documents\PowerShell\Modules ...
  VERBOSE: Import-module -name PowowShell -Global
  VERBOSE: Loading module from path
  'C:\Users\me\Documents\PowerShell\Modules\PowowShell\PowowShell.psm1'.
  VERBOSE: Exporting function 'Invoke-PowowShell'.
  VERBOSE: Exporting alias 'pow'.
  VERBOSE: Importing alias 'pow'.
  VERBOSE: Get-Command "pow"
  VERBOSE: $PowowShell=pow
  Yep, the 'pow' is CmdLet installed
   Type 'pow help' for a list of commands
  
  PS W:\powershell\powowshell&gt; pow help
  pow : The term 'pow' is not recognized as the name of a cmdlet, function, script file, or operable program.
  
  PS W:\powershell\powowshell&gt; Get-Command Invoke-PowowShell
  
  CommandType     Name                                               Version    Source
  -----------     ----                                               -------    ------
  Function        Invoke-PowowShell                                  0.0        PowowShell
  
  </code></pre>
  
  <p>So nothing works and then I manually <code>Import-Module</code>...</p>
  
  <pre><code>PS W:\powershell\powowshell&gt; Import-Module -name PowowShell -Global
  PS W:\powershell\powowshell&gt; pow
  "You have the POWer!"
  </code></pre>
  
  <p>Now it works!</p>