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?

1
  • Could you please try with only Connect-azaccount does the same error appearing..!! Commented Apr 29, 2022 at 17:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.