使用Powershell更改Azure网站Web托管计划模式

5
我一直在阅读以下文章,描述了如何更改您网站的网络托管计划。

http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/

这似乎很好用,但如果我使用相同的命令来更改 Web 托管模式(使用属性:"sku": "Free""sku": "Standard"),它不会给出任何错误反馈,只是返回未更改的(先前的)存储配置。

执行的命令:

$standardServer=@{"sku" = "Standard"; }
Set-AzureResource -Name 'tmtest2' -ResourceGroupName 'Default-Web-JapanWest' -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -PropertyObject $standardServer

有人尝试使用 Powershell 更改 Web 托管模式成功了吗?

编辑:我也尝试了这个链接,它确切地描述了我要实现的目标。但是它没有起作用。

http://msdn.microsoft.com/en-us/library/dn654578.aspx

2个回答

11

我弄清楚了。首先,您需要在默认资源组下创建一个带有“标准”模式的托管计划作为资源。然后,您需要将网站分配给托管计划。

以下是完整的脚本:

Switch-AzureMode AzureResourceManager

Add-AzureAccount

$locations = @('East Asia', 'Southeast Asia', 'East US', 'East US 2', 'West US', 'North Central US', 'South Central US', 'Central US', 'North Europe', 'West Europe', 'Japan East', 'Japan West', 'Brazil South')

$websiteName = Read-Host 'What is the name of your website (without azurewebsites.net)' #tmtest2
$location = Read-Host 'What is the region location of the website'   

if (-Not($locations -contains $location)) {
 throw "location is incorrect, try one of these values: " + (($locations | select -expand $_) -join ", ")
}

$resourceGroupName = 'Default-Web-' + $location.Replace(' ', '');

#create a new web hosting plan - Small Standard machine
$hostingPlanName = $websiteName + 'HostingPlan';
$p=@{"name"= $hostingPlanName;"sku"= "Standard";"workerSize"= "0";"numberOfWorkers"= 1}
New-AzureResource -ApiVersion 2014-04-01 -Name $hostingPlanName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/serverFarms -Location $location -PropertyObject $p -Verbose -Force

$r = Get-AzureResource -Name $websiteName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01
echo $r

$p = $null;
$p = @{ 'serverFarm' = $hostingPlanName }
$r = Set-AzureResource -Name $websiteName -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -PropertyObject $p
#echo $r.Properties

if (-Not($r.Properties['sku'] -eq 'Standard')) {
    throw 'script executed but sku has not been changed'
}

1

启动您的 Azure 资源管理器。

Add-AzureAccount
Switch-AzureMode AzureResourceManager

获取Azure PowerShell API版本 (此链接显示如何)

$DebugPreference='Continue'
Get-AzureResourceGroup
$DebugPreference='SilentlyContinue'

获取您网站资源的名称、资源组名称和资源类型
Get-AzureResource | `
Where-Object { $_.ResourceType -like '*site*' } | `
Format-Table Name, ResourceGroupName, ResourceType

更改目标网站的 Azure 网站托管计划。
Set-AzureResource 
    -Name the-website-name
    -ResourceGroupName 'the-resource-group-name' 
    -ResourceType 'Microsoft.Web/sites'
    -ApiVersion '2014-04-01-preview'
    -PropertyObject @{ 'ServerFarm' = 'the-target-server-farm-name' }

注意事项:

  • 您也可以以类似的方式运行Get-AzureResource
  • 要使用Set-AzureResource更改托管计划,只需要ServerFarm属性。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接