title: How to install a PowerShell module in an Azure Function
body: <p>I need the AWS module, which is available from the PS-Gallery but when I try to run the install step inside an <a href="https://azure.microsoft.com/en-us/services/functions/" rel="noreferrer">Azure Function</a>, it doesn't work. The -verbose argument flag isn't writing anything to the console. </p>
  
  <p>What is the right way to get and use additional PowerShell modules within an Azure function?</p>
  
  <h2>Function code</h2>
  
  <pre><code>[Console]::WriteLine("PowerShell Timer trigger function executed at:$(get-date)");
  if (-not (Get-Module -Name "AWSPowerShell")) {
  [Console]::WriteLine("AWSPowerShell not installed");
  Install-Module -Name AWSPowerShell -Scope CurrentUser -ErrorAction Continue -Verbose
  }
  if (-not (Get-Module -Name "AWSPowerShell")){
  [Console]::WriteLine("AWSPowerShell install step failed");
  }
  </code></pre>
  
  <h2>Function log</h2>
  
  <pre><code>2016-06-09T11:24:31.108 Function started (Id=e09be687-2e13-4754-942e-eab75c8516e5)
  2016-06-09T11:24:32.788 Powershell Timer trigger function executed at:06/09/2016 11:24:32
  AWSPowerShell not installed
  AWSPowerShell install step failed
  2016-06-09T11:24:32.788 Function completed (Success, Id=e09be687-2e13-4754-942e-eab75c8516e5)
  </code></pre>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>Per @travis' answer I added the suggested code, including the nuget package manager line. This still didn't work. I added another debug line and found that there were no module providers, even after trying to add nuget!</p>
  
  <h3>Revised code</h3>
  
  <pre><code>[Console]::WriteLine("Powershell Timer trigger function executed at:$(get-date)");
  
  Get-PackageProvider -Name nuget -ForceBootstrap
  
  $pkg=Get-PackageProvider -ListAvailable
  if ($pkg.Count -lt 1){ [Console]::WriteLine("No providers")}
  
  if (-not (Get-Module -listavailable -Name "AWSPowerShell")) {
      [Console]::WriteLine("AWSPowerShell not installed");
      Install-Module -Name AWSPowerShell -Scope CurrentUser -ErrorAction Continue -Verbose -force
  }
  
  if (-not (Get-Module -listavailable -Name "AWSPowerShell")){
      [Console]::WriteLine("AWSPowerShell install step failed");
  }
  
  Import-Module AWSPowerShell
  </code></pre>
  
  <h3>Revised log</h3>
  
  <pre><code>2016-06-09T17:54:03.859 Powershell Timer trigger function executed at:06/09/2016 17:54:02
  No providers
  AWSPowerShell not installed
  AWSPowerShell install step failed
  2016-06-09T17:54:03.859 Function completed (Success, Id=80efb9fc-5e91-45f9-ab58-3b71fcd764af)
  </code></pre>