2

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'

4 Answers 4

1
$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName 
$myVMName = "srikstest"
$myAdminName ="srikstest"
$myAdminPwd ="NeitherMe"
New-AzureQuickVM -Windows -ServiceName $myVMName -ImageName $VMImage -AdminUsername $myAdminName - Password $myAdminPwd -InstanceSize "ExtraSmall" -Location "Southeast Asia" -Name $myVMName -Verbose

You can create a new Azure service for the virtual machine by specifying either the Location or AffinityGroup parameters, or deploy the new virtual machine into an existing service.

I've just added the location parameter and it worked !!

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I've made some edits aabove based on your suggestion. thanks
1

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

2 Comments

The service name should be globally unique definitely, since it is the DNS name (*.cloudapp.net). <br/> New-AzureQuickVM will check if the cloud service exists, it would use if it exists other wise try to create. But while it tries to create it will fail if either Affinity group or Location is not specified, may be that is what has happened with your script.
I was seeing the same issue and this post was very helpful indeed. Thanks for that. Remember in addition to adding -Location parameter you also need to change the ServiceName. Without changing the ServiceName the command continued to fail for me. Very unintuitive & most likely an azure bug.
0

Assign/replace the value to variable.

New-AzureVMConfig -Name $VmName -InstanceSize $InstanceSize -Label $VmName -ImageName $Imagename -DiskLabel $DiskLabel | add-azureprovisioningconfig -LinuxUser $cred.GetNetworkCredential().Username -Linux -Password $cred.GetNetworkCredential().Password -SSHPublicKeys $sshkey | Add-AzureEndpoint -LocalPort $LocalPort1 -Name $LocalPortName1 -Protocol tcp -PublicPort $LocalPort1 | New-AzureVM -ServiceName $CloudServiceName -AffinityGroup $AffinityGroup –WaitForBoot

Comments

0

----create using following command

New-AzResourceGroup -Name "VM_RG" -Location "CentralIndia"

ResourceGroupName : VM_RG Location : centralindia ProvisioningState : Succeeded Tags : ResourceId : /subscriptions/2d0e0115-72f7-422b-8816-0ee2e9af655d/resourceGroups/VM_RG

PS /home/dinesh> New-AzVM -Name "VMusingPS" -ResourceGroupName "VM_RG" -Location "CentralIndia" -Credential (Get-Credential)

PowerShell credential request

Enter your credentials.

User: dinesh Password for user dinesh: ***********

No Size value has been provided. The VM will be created with the default size Standard_D2s_v3.

ResourceGroupName : VM_RG
Id : /subscriptions/2d0e0115-72f7-422b-8816-0ee2e9af655d/resourceGroups/VM_RG/providers/Microsoft.Compute/virtualMachines/VMusingPS VmId : 0a48f779-f6c8-4e2f-b9a6-21ce6dc617b7
Name : VMusingPS
Type : Microsoft.Compute/virtualMachines
Location : centralindia
Tags : {}
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
SecurityProfile : {UefiSettings, SecurityType}
OSProfile : {ComputerName, AdminUsername, WindowsConfiguration, Secrets, AllowExtensionOperations, RequireGuestProvisionSignal} ProvisioningState : Succeeded
StorageProfile : {ImageReference, OsDisk, DataDisks, DiskControllerType}
FullyQualifiedDomainName : vmusingps-a45025.CentralIndia.cloudapp.azure.com
TimeCreated : 10/1/2024 9:14:49 AM
Etag : "2"

PS /home/dinesh>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.