1

Now I can execute Powershell Azure cmdlets and scripts from my ASP MVC web app when is running locally, but when I do a deployment to Azure Web Sites the Powershell Azure cmdlets doesn't work.

Error message:

The term 'Get-AzureSubscription' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I guess it does not work because the "azure cmdlets" are not installed on the web server

What I can do? Any advice?


Hi again, Im now testing the application hosted in a IIS8 in Azure Virtual Machine, but again when the app is deployed to the server I cannot use the Azure Cmdlets, the Azure cmdlets are already installed on the Virtual Machine.

When I debug the app in the VM with Visual studio I can use the cmdlets, but when the app is deployed the cmdlets are no recognized.

There is something else that I need to setup in order to use the Azure cmdlets???


This is an example of one function, the function populate a dropdownlist with the result, in localhost it works fine, in IIS.

public IEnumerable<SelectListItem> getImageFamily()
    {
        var shell = PowerShell.Create();
        shell.Commands.AddScript("C:\\inetpub\\wwwroot\\appName\Scripts\\test.ps1");
        Collection<PSObject> results = shell.Invoke();

        List<SelectListItem> items = new List<SelectListItem>();
        foreach (var psObject in results)
        {
            string image = psObject.BaseObject.ToString();
            items.Add(new SelectListItem { Text = image, Value = image });
        }
        return items;
    }

Then this is the simple script

(Get-AzureVMImage).ImageFamily | sort -Unique

I also tried

Import-Module -Name "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure"

(Get-AzureVMImage).ImageFamily | sort -Unique

And also tried (I cut some code...)

public IEnumerable<SelectListItem> getImageFamily()
    {
        ...
        shell.Commands.AddScript("(Get-AzureVMImage).ImageFamily | sort -Unique");
        Collection<PSObject> results = shell.Invoke();
        ...
    }
1

1 Answer 1

1

To answer the specific question, no it is not possible to do this in Azure Web Apps (formerly Azure Websites).

You have some options though.

  1. The PowerShell cmdlets, for the most part, wrap the Service Management API and Resource Manager API. These are REST API's so depending on what you are trying to do, you could probably just use these instead and call the API directly from your application using HTTP/S calls. I would strongly recommend taking this approach.

  2. If you really must take a dependency on Azure PowerShell from your application, then you could use an Azure Cloud Service Web Role instead and install the Azure PowerShell cmdlets using a Startup Task.

  3. You could take an IaaS approach and host your own IIS server (or server farm) in Azure Virtual Machines where you get full control of the configuration of the machine. Of course, you also take on full responsibility for maintaining your VM(s) if you take this approach.

Personally, I would do everything I could to avoid options 2 and 3. It's just not good design. To some degree I regret even mentioning them because you will likely run into other issues trying to get them to work. But, I wanted to be thorough in my answer.

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

9 Comments

Thanks for the answer, My app requiere a lot of specific Powershell Azure cmdlets so the best path that I can take is third one.
Hi again, Im now testing the aplication hosted in a IIS8 in Azure Virtual Machine, but again when the app is deployed to the server I cannot use the Azure Cmdlets, the Azure cmdlets are already installed on the Virtual Machine. When I debug the app in the VM with Visual studio I can use the cmdlets, but when the app is deployed the cmdlets are no recognized. There is something else that I need to setup in order to use the Azure cmdlets???
The worker process for IIS won't have the same environment variables (ie: %path%) that your development environment has. So, you will probably need to reference them using the full path. It's hard to say for sure though without seeing how you are invoking the cmdlets.
Hi, thanks for the aswerI updated the question with an example, also I dont understand well what you mention about the enviroment variables :S
Since you chose option 3 I would suggest RDP'ing into the VM & making sure you have PowerShell working correctly. Then, try it from IIS running locally on the VM. Frankly, I don't see a need for PowerShell given what you've said you're doing. Everything can be done with simple REST calls (option 1) & is what I would recommend here so you avoid all this. Invoking another process from IIS/W3WP is just not good design. Something else that could be causing you problems is that the process you're using to run PS from may have limited privileges. Just a thought though - not saying that is the issue.
|

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.