0

I've a webjob running in an azure app service that uses runspace to execute azure powershell module commands. Locally it's working fine because I can install az module directly using Windows powershell but when I deploy it to Azure, it fails.

Initially I was getting following error when I was executing Connect-AzAccount -Identity

Connect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet

Then I tried to install az module inside of a runspace and I started getting another error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Here is how I'm trying to install az module:

    runSpace.Open();

    RunspaceInvoke scriptInvoker = new RunspaceInvoke();
    scriptInvoker.Invoke("Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser");
    scriptInvoker.Invoke("Import-PackageProvider Nuget");
    scriptInvoker.Invoke("Install-Module Az.Websites -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Websites");
    scriptInvoker.Invoke("Install-Module Az.Storage -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Storage");

So is it possible to execute az powershell module command in appservice?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Ask
  • 3,076
  • 6
  • 30
  • 63

1 Answers1

0
  • There are multiple ways to address the issue, below are the few resolutions.

Fix 1: To resolve the issue run the below command.

Import-Module Az.Accounts

When you executed the above command, it will prompt you for the credentials.

Fix 2:

  • Install the Module Az. By using the below PowerShell cmdlet,
Import-Module Az
  • Connect to the AzAccount like below,
Connect-AzAccount
  • You can check the worked solution from here.

  • Also check this SO with the related discussions.

RajkumarPalnati
  • 541
  • 2
  • 6