使用混合使用权益运行New-AzureRmVm的Powershell出错

时间:2016-11-20 16:27:00

标签: powershell azure deployment virtual-machine

我为非营利组织提供了一个有效的Azure赞助订阅,与“个人”类型的Microsoft帐户相关联。我已成功将通用VHD上传到存储帐户(使用以下脚本的注释部分中的命令),现在我正在尝试基于该模板部署VM。

每次运行以下脚本时,都会抛出错误并在最后一行死掉,错误

New-AzureRmVM : The requested tier for resource '/subscriptions/<removed>/resourceGroups/CCo
FRockResourceGroup/providers/Microsoft.Compute/virtualMachines/CCoFRockIIS' is currently not available in location
'West US' for subscription '<removed>'. Please try another tier or deploy to a different
location.
ErrorCode: SkuNotAvailable
ErrorMessage: The requested tier for resource '/subscriptions/<removed>/resourceGroups/CCoFR
ockResourceGroup/providers/Microsoft.Compute/virtualMachines/CCoFRockIIS' is currently not available in location 'West
US' for subscription '<removed>'. Please try another tier or deploy to a different location.
StatusCode: 409
ReasonPhrase: Conflict
OperationID : 8d2f838c-56c4-4237-ad5e-19357e525e17
At CreateAzureIISServer.ps1:35 char:1
+ New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $locati ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmVM], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

我尝试了多种VM大小 - 我认为这不是它所指的。

作为另一个数据点,基于另一个脚本,当我运行Add-AzureVmImage时,它告诉我

add-azurevmimage : BadRequest: The storage account with the name ccofrockstorageaccount as specified in the VHD URI
https://ccofrockstorageaccount.blob.core.windows.net/ccofrockcontainer/CCoFBoilerplate.vhd does not exists in the
current subscription <removed>.
OperationID : 'a41daf3cfba33eceb34e51d1dcc49e8d'
At line:1 char:1
+ add-azurevmimage -imagename "CCoFBoilerplate" -MediaLocation "https://ccofrockst ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Add-AzureVMImage], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.DiskRepository.AddAzureVMImage

即使我运行Add-AzureAccount和Get-AzureRmSubscription,它们也会返回正确的SubscriptionId - 与使用Azure Web门户时可以看到我的存储帐户的ID相同。

这是我用来尝试添加此VM的脚本 - 任何人都可以通过弄清楚脚本为什么会窒息来帮助我吗?我怀疑使用“个人”类型的MS帐户而不是公司类型的问题,但我可能是错的。请注意,对于get-credential命令,我提供了唯一的(不存在的)凭据 - 我认为这应该是新服务器上的用户登录。另外两次我被提示登录,我正在使用我的“个人”MSA凭据,它确实表明它正在“按照预期将我重定向到Microsoft帐户登录”。感谢

$cred = Get-Credential
$location = "West US"
$resourceGroupName = "CCoFRockResourceGroup"
$containerName = "ccofrockcontainer"
$publicIPName = "CCoFRockPublicIP"
$subnetName = "CCoFRockSubnet"
$nicName = "CCoFRockIISPublic"
$vnetName = "CCoFRockVnet"
$vmName = "CCoFRockIIS"
$computerName = "CCoFRockIIS"
$osDiskName = "CCoFRockIIS.vhd"
$templateDiskName = "CCoFBoilerplate.vhd"
$vmSize = "Standard_D2_v2"
$storageAccountName = "ccofrockstorageaccount"
$urlOfUploadedImageVhd = "https://$storageAccountName.blob.core.windows.net/$containerName/$templateDiskName"


add-azureaccount
Login-AzureRmAccount
##########
#get-azurermsubscription
#select-azurermsubscription -subscriptionid <removed>#new-azurermresourcegroup -name $resourceGroupName -Location $location
#new-azurermstorageaccount -resourcegroupname $resourceGroupName -name $storageAccountName -Location $location -SkuName "Standard_LRS" -Kind "Storage"
#Add-AzureRmVhd -ResourceGroupName $resourceGroupName -Destination "https://$storageAccountName.blob.core.windows.net/$containerName/$templateDiskName" -LocalFilePath "Azure2016.vhd"
##########
$publicIP = New-AzureRmPublicIpAddress -Name $publicIPName -ResourceGroupName $resourceGroupName -Location $location -AllocationMethod Static
$subnetconfig = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/8
$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix 10.0.0.0/8 -Subnet $subnetconfig
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $resourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIP.Id
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
$osDiskUri = '{0}vhds/{1}{2}.vhd' -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption FromImage -SourceImageUri $urlOfUploadedImageVhd -Windows
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm -LicenseType Windows_Server

2 个答案:

答案 0 :(得分:1)

如果你去azure portal尝试重新创建步骤,你会得到一条类似于这个的消息 enter image description here

消息显示“您的订阅不支持在美国西部创建虚拟机。请选择其他位置。支持的位置是:美国东部,美国中南部,西欧,东南亚,美国西部2,美国中西部,韩国中部,韩国南部“

只需更改为West US 2即可使用

答案 1 :(得分:1)

也许不是你的情况,但这可能有助于在堆栈工作流程中搜索skuNotAvailable的人

我在the quickstart docs

之后创建一个简单的vm时遇到了同样的错误
#!/bin/bash

# Create a resource group.
az group create --name myResourceGroup --location westeurope

# Create a new virtual machine, this creates SSH keys if not present.
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys

我刚刚发现该位置会影响计算机的imagesize的可用性。 未指定--size选项,aws-cli使用的默认大小Standard_DS_v2在westeurope

中不可用