如何使用Powershell Commandlet在App Service Environment中创建Azure WebApp

时间:2015-05-18 06:01:14

标签: powershell azure

我一直在尝试使用Powershell命令行开关在App Service环境中创建Azure Web App

我无论如何都无法指定我的App Service Environment应该与New-AzureWebApp或New-AzureAppServicePlan命令行开关一起使用

在Web门户中,您将App Service Environment指定为位置......但Powershell Commandlets似乎无法做到这一点(它们验证该位置是有效的“常规”Azure位置)。

3 个答案:

答案 0 :(得分:5)

回答我自己的问题:

我发现可以使用New-AzureResourceGroup命令行开关和自定义JSON模板创建新的Web App。我找不到在库中的ASE中配置Web App的任何模板,但是通过对门户使用的模板进行逆向工程,并从库中修改Microsoft.WebSite.0.3.17-preview.json模板,我可以使用以下命令创建WebApp:

New-AzureResourceGroup -Name $ResourceGroupName -Location "Australia Southeast" -TemplateFile $TemplateFile -siteName $SiteName -hostingPlanName $HostingPlanName -hostingEnvironment $HostingEnvironment -siteLocation "Australia Southeast" -workerSize 0 -sku "Premium"

使用$ TemplateFile变量,该变量包含以下模板文件的路径:

http://pastebin.com/VefC0Dz2

这只是图库中的0.3.17预览模板,具有以下修改:

添加hostingEnvironment参数

"parameters": { "hostingEnvironment": { "type": "string", "defaultValue": "" },

将hostingEnvironment属性添加到Microsoft.Web / serverfarms资源:

"resources": [ { "apiVersion": "2014-06-01", "name": "[parameters('hostingPlanName')]", "type": "Microsoft.Web/serverfarms", "location": "[parameters('siteLocation')]", "properties": { "name": "[parameters('hostingPlanName')]", "sku": "[parameters('sku')]", "workerSize": "[parameters('workerSize')]", "hostingEnvironment": "[parameters('hostingEnvironment')]", "numberOfWorkers": 0 } }, { "apiVersion": "2014-06-01", "name": "[parameters('siteName')]", "type": "Microsoft.Web/sites", "location": "[parameters('siteLocation')]", "tags": { "[concat('hidden-related:', '/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty" }, "dependsOn": [ "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]" ], "properties": { "name": "[parameters('siteName')]", "serverFarm": "[parameters('hostingPlanName')]", "hostingEnvironment": "[parameters('hostingEnvironment')]" } },

我认为这可能也可以使用Add-AzureResource Commandlet完成,但我还没有尝试过。

答案 1 :(得分:2)

Microsoft已将ResourceManager CommandLets添加到PowerShell。这允许您执行部署。可以使用以下命令在powerShell中创建网站:

yourApp.controller("yourController", ['$scope', '$http', '$timeout', 'localStorage',
    function ($scope, $http, $timeout, localStorage) {

        var synchronization = function () {
            if (localStorage.getItem('job_id') != "" && localStorage.getItem('job_id') > 0) {

                if (localStorage.getItem('job_id.done_tasks') != "" && localStorage.getItem('job_id.done_tasks') > 0) {
                    $scope.done_tasks = {};
                    $scope.done_tasks = localStorage.getItem('job_id.done_tasks');
                    $scope.job_id = localStorage.getItem('job_id');

                    var userData = $http({
                        method: "post",
                        url: "http://localhost/t-app/mobile-data/update-tasks.php",
                        data: {
                            done_tasks: $scope.done_tasks,
                            job_id: $scope.job_id
                        },
                        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                    });
                    userData.success(function (userdataobject) {
                        //* I added response to $scope *//
                        $scope.status_id = userdataobject["status_id"];
                        $scope.message = userdataobject["message"];

                        localStorage.setItem('job_id', '');
                        localStorage.setItem('job_id.done_tasks', '');

                        $timeout(synchronization, 2000);
                    });
                }
            }
        };

    }]);

您需要为属性创建一个对象:

New-AzureRmResource -Location "West Europe" -Properties $props 
-ResourceName "Site1" -ResourceType "microsoft.web/sites"
-ResourceGroupName "ResourceGrp1" -Force

通过在现场网站上使用Get-AzureRMResource,您可以了解属性的特性。

答案 2 :(得分:0)

最近,Microsoft将Azure网站更改为Azure WebApps。但是,PowerShell cmdlet命令保持不变。

所以你必须使用New-AzureWebsite