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.
:(