New-AzureVm: CurrentStorageAccount is not accessible

This is just a really quick post, which I hope will help anyone else who gets this “error”.

This post is quite old now, and Azure has changed a fair deal since this was written. This is unlikely to still be a problem now.

The Problem

Basically, I’ve been working on a build script for an Azure project. I’d tested my various scripts and commands in isolation, and all of them seemed to be working fine on their own. However, when it got to putting them all together, I kept getting an error when trying to create the Virtual Machine stating “New-AzureVm : CurrentStorageAccount is not accessible. Ensure the current storage account is accessible and in the same location or affinity group as your Cloud service.”

The script I was using looked like this:

1
2
3
4
5
New-AzureService -ServiceName $build.CloudService -AffinityGroup $build.AffinityGroup$dns = New-AzureDNS -Name $build.DnsName -IPAddress’10.0.0.4
New-AzureVMConfig -Name $build.AdVmName -InstanceSize $build.AdVmSize -ImageName $build.AdVmImage |
Add-AzureProvisioningConfig -Windows -Password$build.AdVmPassword |
Set-AzureSubnet -SubnetNames $build.SubnetName |
New-AzureVM -ServiceName $build.CloudService -VNetName $build.VNetName -DnsSettings $dns -AffinityGroup$build.AffinityGroup

Obviously, the cause of this error could simply be that the Storage Account and Cloud Service are in different Locations or Affinity groups. After confirming this was not the cause, and verifying that I could create a VM in that Storage Account through the Management Portal, I went back through my scripts to see where I’d gone wrong

The Solution

The issue was that I was trying to use the AffinityGroup parameter when provisioning the VM. This should only be used when you are creating a new implicit cloud service as part of the provisioning. If you are getting this error, you have two options. The first is to specify a cloud service that doesn’t yet exit and let Azure create if for you as part of this command. Alternatively, you can also remove the –AffinityGroup parameter and specify a Cloud Service that has already been created. To fix this script I simply removed the parameter, to make the last line

1
New-AzureVM -ServiceName $build.CloudService -VNetName $build.VNetName -DnsSettings $dns

You should then be able to carry on powershelling your Azure environment. Hope this helps.