james3mg
james3mg

Reputation: 93

Error in Powershell running New-AzureRmVm using hybrid use benefit

I've got an active Azure Sponsorship subscription for non-profits, tied to a "personal" type Microsoft Account. I've uploaded a generalized VHD to the storage account successfully (using the commands in the commented portion of the below script), and now I'm trying to deploy a VM based on that template.

Every time I run the following script, it throws an error and dies on the last line, with the error

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

I have tried multiple VM sizes- I don't think that's what it's referring to.

As another data point, based on another script, when I run Add-AzureVmImage, it tells me

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

Even though when I run Add-AzureAccount and Get-AzureRmSubscription, they return the correct SubscriptionId - the same ID as I can see my storage account in using the Azure Web Portal.

Here is the script I'm using to try and add this VM- can anyone help me out by figuring out why the script is choking? I suspect an issue with using a "personal" type MS account rather than a corporate type, but I could be wrong. Note that for the get-credential command I'm providing unique (non-existent) credentials - which I believe is supposed to be the user login at the new server. The other two times I'm prompted to login, I'm using my "personal" MSA credentials and it does indicate that it's "redirecting me to Microsoft account login" as expected. Thanks

$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

Upvotes: 0

Views: 776

Answers (2)

Daniele Murroni
Daniele Murroni

Reputation: 71

Maybe it's not your case but this may help someone who search for skuNotAvailable on stack workflow

I got the same error while creating a simple vm following the quickstart docs

#!/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

I've just discovered that the location affects the availability of both the image and the size of a machine. Not specifying the --size option, the aws-cli was using the default size Standard_DS_v2 which is not available in westeurope

Upvotes: 1

MrIsaac
MrIsaac

Reputation: 11

If you go to the azure portal and try and recreate the steps, you'll get a message similar to this one enter image description here

The message reads "Your subscription doesn't support virtual machine creation in West US. Choose a different location. Supported locations are; East US, South Central US, West Europe, Southeast Asia, West US 2, West Central US, Korea Central, Korea South"

Simply need to change to West US 2 for this to work

Upvotes: 1

Related Questions