5

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

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

这似乎工作正常,但如果我使用相同的命令来更改网络托管模式(使用 property: "sku": "Free"to "sku": "Standard")它不会给出任何错误反馈,并且只会返回未更改的(以前的)存储配置。

执行的命令:

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

有人有幸使用 Powershell 更改虚拟主机模式吗?

编辑:我也尝试了这个链接,它准确地描述了我想要实现的目标。然而它没有用。

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

4

2 回答 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'
}
于 2014-07-23T10:11:05.760 回答
1

启动 Azure 资源管理器。

Add-AzureAccount
Switch-AzureMode AzureResourceManager

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

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

获取网站资源的名称、ResourceGroupName 和 ResourceType

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属性。
于 2014-10-01T01:02:43.267 回答