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();
...
}