我一直在阅读以下文章,该文章介绍了如何更改网站的网络托管计划。
这似乎工作正常,但如果我使用相同的命令更改网络托管模式(使用属性:"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改变网络托管模式的运气吗?
修改: 我也尝试过这个链接,它准确地描述了我想要实现的目标。然而它没有用。
答案 0 :(得分: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 :(得分:1)
启动Azure资源管理器。
Add-AzureAccount
Switch-AzureMode AzureResourceManager
获取Azure PowerShell API版本(This link shows how)
$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
属性。