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?