2015-04-22 57 views
1

现在,我可以在本地运行时从我的ASP MVC Web应用程序执行Powershell Azure cmdlet和脚本,但是当我部署到Azure网站时,Powershell Azure cmdlet不起作用。是否可以从Web应用程序执行Powershell Azure CMDlet?

错误消息:

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.

我想这是行不通的,因为“天蓝色的cmdlet”没有Web服务器

我能做些什么上?有什么建议?


嗨再次,即时通讯目前正在测试在Azure中的虚拟机一个IIS8托管的应用程序,但同样,当应用程序部署到我不能使用Azure中的cmdlet的服务器上,在Azure的cmdlet已经安装在虚拟机。

当我用Visual Studio在VM中调试应用程序时,我可以使用cmdlet,但是当部署应用程序时,cmdlet不会被识别。

还有一些我需要设置才能使用Azure cmdlet?


这是一个功能的一个例子,该函数填充下拉列表,其结果,在本地主机能正常工作,在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; 
    } 

那么这是一个简单的脚本

(Get-AzureVMImage).ImageFamily | sort -Unique 

我也试过

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

(Get-AzureVMImage).ImageFamily | sort -Unique 

而且还试图(我切一些代码...)

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

你想做什么?我对Azure网站了解不多,但您需要安装Azure PowerShell才能使用这些cmdlet:http://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/ –

回答

1

要回答具体的问题,不,在Azure中无法做到这一点Web Apps(以前称为Azure网站)。

虽然你有一些选择。

  1. 的PowerShell命令,在大多数情况下,包裹Service Management APIResource Manager API。这些REST API取决于你想要做什么,你可以直接使用它们,并使用HTTP/S调用直接从应用程序调用API。 我强烈建议采取这种方法

  2. 如果您确实必须从您的应用程序中依赖于Azure PowerShell,那么您可以使用Azure Cloud Service Web角色,而使用Startup Task安装Azure PowerShell cmdlet。

  3. 您可以采用IaaS方法,并在Azure虚拟机中托管您自己的IIS服务器(或服务器场),从而完全控制机器的配置。当然,如果你采取这种方法,你也承担着维护虚拟机的全部责任。

就个人而言,我会尽我所能避免选项2和3.这只是不好的设计。在某种程度上,我甚至提到他们,因为你可能会遇到其他问题,试图让他们工作。但是,我想在我的答案中彻底。

+0

感谢您的回答,我的应用程序需要很多特定的Powershell Azure cmdlet,因此我可以采用的最佳路径是第三个。 – TassadarCRG

+0

嗨,我现在正在测试Azure虚拟机中的IIS8中托管的应用程序,但再次将应用程序部署到服务器时,我无法使用Azure Cmdlet,Azure cmdlet已安装在虚拟机上。 当我用Visual Studio在VM中调试应用程序时,我可以使用cmdlet,但是当部署应用程序时,cmdlet不会被识别。 还有一些我需要设置才能使用Azure cmdlet? – TassadarCRG

+1

IIS的工作进程不会具有与您的开发环境相同的环境变量(即:%path%)。所以,你可能需要使用完整路径来引用它们。尽管没有看到你如何调用cmdlet,但很难说清楚。 –

相关问题