title: Run Azure PowerShell script in Docker container
body: <p>I would like to run an Azure-PowerShell script in a Docker container. As Docker is quite new to me, maybe I just do not understand some concepts correctly.</p>
  <p>As far as I understand, the Dockerfile below is based on <strong>Linux</strong>, and has <em>PowerShell</em> and <em>Azure PowerShell</em> installed?</p>
  <pre><code>FROM mcr.microsoft.com/azure-powershell:latest
  COPY . /app
  SHELL [&quot;cmd&quot;, &quot;/S&quot;, &quot;/C&quot;]    
  RUN &quot;&amp; ./app/WriteHostTest.ps1&quot; #For testing purposes I just want to fire a really simple .ps1 file.
  </code></pre>
  <p>I tried various modifications, but currently I get this error:</p>
  <pre><code>container_linux.go:349: starting container process caused &quot;exec: \&quot;cmd\&quot;: executable file not found in $PATH&quot;
  </code></pre>
  <p>In a &quot;<strong>Windows container&quot;</strong> it is working, however, here I just cannot manage to install the Az PowerShell module. I also tried a lot of modifications, but basically:</p>
  <p>The Dockerfile:</p>
  <pre><code>## Create first layer: Windows image
  FROM mcr.microsoft.com/windows/servercore:ltsc2019
  LABEL Robin Bette
  
  ## Create second layer: copy everything from the CURRENT DIRECTORY to /app location
  COPY . /app
  
  ## Download the tools 
  SHELL [&quot;cmd&quot;, &quot;/S&quot;, &quot;/C&quot;]
  ADD &quot;https://dist.nuget.org/win-x86-commandline/v5.8.0/nuget.exe&quot; &quot;C:\TEMP\nuget.exe&quot;
  
  ## Install NuGet
  RUN &quot;C:\TEMP\nuget.exe&quot; install NuGet.Build -Version 2.12.1
  
  ## Install PowerShellGet
  SHELL [&quot;powershell&quot;, &quot;-ExecutionPolicy&quot;, &quot;Bypass&quot;, &quot;-Command&quot;]
  RUN Install-Module -Name PowerShellGet -RequiredVersion 2.2.1 -Force
  
  # Install Azure PowerShell
  RUN Install-Module -Name Az -Force
  
  ## Run the PowerShell script
  RUN PowerShell ./app/Az-Script.ps1
  
  
  ## Stuff I tried:
  # Install PS7 (did not help)
  # RUN iex &quot;&amp; { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI&quot; =&gt; Error on the ampersand
  #ADD &quot;https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/PowerShell-7.1.0-win-x64.msi&quot; &quot;C:\TEMP\PowerShell-7.1.0-win-x64.msi&quot;
  #RUN &quot;C:\TEMP\PowerShell-7.1.0-win-x64.msi&quot;
  
  #RUN Install-PackageProvider -Name NuGet -Force
  #RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://aka.ms/install-powershell.ps1'))
  
  Install-PackageProvider : No match was found for the specified search criteria
  for the provider 'NuGet'. The package provider requires 'PackageManagement'
  and 'Provider' tags. Please check if the specified package has the tags.
  Exception calling &quot;ShouldContinue&quot; with &quot;2&quot; argument(s): &quot;Object reference not set to an instance of an object.&quot;
  </code></pre>
  <p>Here, I just keep getting the error (for which I tried also various solutions like updating PowerShell to version 7):</p>
  <pre><code>Exception calling &quot;ShouldContinue&quot; with &quot;2&quot; argument(s): &quot;Object reference not set to an instance of an object.&quot; At...\PowerShellGet\1.0.0.1\...
  </code></pre>
  <p>Any thoughts? Thanks in advance!</p>