1
votes

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
What is it that you want to do? I don't know much about Azure websites, but you do need azure powershell to be installed in order to use these cmdlets: azure.microsoft.com/en-us/documentation/articles/…Erti-Chris Eelmaa

1 Answers

1
votes

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.