Not able to run powershell commands from ASP.Net code

I have an ASP.Net application that tries to execute the ‘az login’ command on Azure using power shell commands. Below is the code that I am using:


PowerShell powershell = PowerShell.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace())
powershell.Runspace = runspace;
PSCommand PScmd = new PSCommand();
string cmdStr = “az login -u ‘’ -p ‘*******’”;
var results = powershell.Invoke();



When this code is executed locally, it runs successfully, but when I deploy the same code on Azure app service and browsethe service, I get an error message saying ‘az is not recognized as the name of a cmdlet’. I even went to the ‘Kudu’ powershell where the code is deployed and tried to run the same command there but still got the same error. Please suggest what needs to be done in this case.

See these articles

Calling a PowerShell Script From Your .NET Code

Using PowerShell 2.0 from ASP.NET Part 1

Making a powershell script run from aspx

Execute PowerShell from a ASP.NET Web Application