Search code examples
powershellazure

Creating a VM in Azure using Powershell


I am trying to create a VM in Azure using powershell. I am running this on my local PC. I have been able to setup websites and SQL Azure instances without any issues but None of the samples on the web work.

Import-Module Azure
Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Cloud\Azure.publishsettings"

$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName 
$myVMName = "jsTestVM1"
$myAdminName ="jsTestAdmin1"
$myAdminPwd ="not telling you"
New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVMName -AdminUsername $myAdminName -Password $myAdminPwd -InstanceSize "ExtraSmall"

I get the following message:

New-AzureQuickVM : ResourceNotFound: The hosted service does not exist.
At line:1 char:1
+ New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVM ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureQuickVM], CloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM

I've tried samples from the web and they give the same error message as well.

Edit:

If I specify a location I get the error message 'Service already exists, Location cannot be specified'. If I specify AffinityGroup I get 'Service already exists, AffinityGroup cannot be specified'


Solution

  • In the end I added an affinity group and changed the service name I was using. This enabled me to create the VM. The service name I was using was not in use as far as I was aware in my subscription so either a previous failed install left some artefact around or the name needs to be globally unique. I've checked the docs here http://msdn.microsoft.com/en-us/library/azure/dn495183.aspx and it doesn't state the service name needs to be globally unique