2

Im working on an ASP MVC app that automates some Azure services, like create a VM. In order to do that im using Azure Powershell cmdlets.

The app will be hosted in an Azure VM with IIS and SQL Server, I already install the Azure cmdlets module to manage de Azure services, I already tested the cmdlets using my Azure subscription, they worked well in the VM.

When im debugging the app on localhost using localDB and IIS EXPRESS the cmdlets are successfully recognized and work well, but when I deploy the application to the IIS the CMDlets are not recognized.

"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."

What Im missing? what i have to setup in order to run the cmdlets from my the deployed app on the IIS?

Uopdate: This is an example of one function, the function populate a dropdownlist with the result, in localhost it wor 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();
        ...
    }

When I run the instruction inside a script file I got:

The term 'C:\inetpub\wwwroot\appName\Scripts\test.ps1' 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.

:(

2
  • Have you installed Azure PowerShell modules on IIS? Commented May 7, 2015 at 5:50
  • the Azure Powershell module is installed on the VM where is located the IIS, dont know if I have to setup something else in the IIS. Commented May 7, 2015 at 14:32

1 Answer 1

1

Iv'e encountered this problem while trying to auto deploy into azure aswell

the solution in my case was loading the modules inside the script

Write-Verbose "Improt Azure Powershell cmdlets"
Import-Module -Name "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure"
Import-Module -Name "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager"

P.S. make sure the paths are the same in your VM's

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

4 Comments

Damm my Azure subscription just expired today, I will try as soon as I can re-use Azure >.<
Well seens that I cannot even run the script The term 'C:\pathtoscript\import.ps1' 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 just ran that import statement and now Get-AzureVM no longer works. How would I reset this?
I just repaired the Powershell Azure install from remove programs. Still not sure how to repair that in script though.

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.