question

FisherEthan-5907 avatar image
0 Votes"
FisherEthan-5907 asked FisherEthan-5907 commented

Azure not creating VMs via PowerShell

I am working the tutorial
Load balance Windows virtual machines in Azure to create a highly available application with Azure PowerShell" https://docs.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-load-balancer for a college class. The first time I did this tutorial the code for creating VMs created myVM1 and myVM3 but not myVM2. After I executed the 'New-AZVM command loop the following output appeared.


Id Name PSJobTypeName State HasMoreData Location Command


2 Long Running O… AzureLongRunni… Running True localhost New-AzVM
3 Long Running O… AzureLongRunni… NotStarted False localhost New-AzVM
4 Long Running O… AzureLongRunni… NotStarted False localhost New-AzVM

Because myVM2 was not created the command for installing IIS extension didn't work as they resulted in the error:

Set-AzVMExtension:
Line |
3 | Set-AzVMExtension -ResourceGroupName "etfisher-TechEx05" -ExtensionNa …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Can not perform requested operation on nested resource. Parent resource 'myVM2' not found.
ErrorCode: ParentResourceNotFound
ErrorMessage: Can not perform requested operation on nested resource. Parent resource 'myVM2' not found.
ErrorTarget:
StatusCode: 404
ReasonPhrase: Not Found

I deleted the resource group and all resources and started completely over. Now when I get to the stage to execute the New-AZVM command loop no VM is created. The output after execution was:

Id Name PSJobTypeName State HasMoreData Location Command


2 Long Running O… AzureLongRunni… Running True localhost New-AzVM
3 Long Running O… AzureLongRunni… Running True localhost New-AzVM
4 Long Running O… AzureLongRunni… Running True localhost New-AzVM

Why are the VMs not being created in Azure with this code? First just "myVM2", and now no VMs. Every other resource appears in the resource group but the VMs.

azure-virtual-machines
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered FisherEthan-5907 commented

Hello @FisherEthan-5907 ,
Thanks for reaching out to Microsoft Q&A Platform.
I would recommend 2 things from that document:

1) The powershell code where it tries to create the VM, those commands are running as "JOB" in the back ground - so it will take time for the VMs to be created. Sometimes if the VM creation fails you won't be able to track the failures as the JOB is running in the back end.

Recommendation is:-
From the code of VM creation in For Loop section , remove the last part -AsJob , so that you can see the progress of VMs creation on the screen before you go-ahead and install IIS

for ($i=1; $i -le 3; $i++)
{
New-AzVm -ResourceGroupName "myResourceGroupLoadBalancer"
-Name "myVM$i" -Location "East US"
-VirtualNetworkName "myVnet" -SubnetName "mySubnet"
-SecurityGroupName "myNetworkSecurityGroup" -OpenPorts 80
-AvailabilitySetName "myAvailabilitySet" -Credential $cred

}

Second Recommendation:

Try to copy all those commands in a Powershell script and execute that particular script instead of individual commands. Again remove that -AsJob paramater in the For Loop as a part of VM creation.


Let us know if that helps !

Regards,
Shiva.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Removing -AsJob was a great suggestion. This allowed me to see the progress of the VM creation. It also provided output on errors which I was not getting with the -AsJob parameter. Combining all the code into a script was also a great suggestion. This allowed the VMs to be created before installing the ISS extension. When the VM creation was running -AsJob I didn't know when they were done so I could execute the last part of the tutorial.

Since I was able to see the error codes it appears the problem was related to a limit on the vCPU cores in my region. The region I was trying to create the VMs in for this tutorial had a vCPU limit of 6. I had 2 VMs already, each with 1 vCPU core. The default size for a VM when executing this code is Standard D2S v3 which creates VMs with 2 vCPUs each. When I executed cmdlet Get-AzVmUsage I was able to see that the vCPU limit for D2S family size in the region I am using is 4. Since this code creates 3 VMs of size Standard D2S v3 each using 2 cores for a total of 6, this exceeded the limit of 4 for the D2S family size. I think if I was on a pay as you go account instead of a student account this may not have been an issue. I tried to increase my vCPU quota but I was unable to due to my student account which has a credit limit, not a pay as you go model.

I ended up specifying a size in the New-AzVM cmdlet of -Size "Standard_DS1_v2" which uses only 1 vCPU per VM and kept me under my quota.

1 Vote 1 ·

Thank you. I will remove the -AsJob parameter from the New-AzVm for loop and try and run all the code in a Powershell script.

I want to make sure I have all the syntax correct as there are variations within the tutorial. In the for loop for the for the New-AzNetworkInterface the -Name value is NOT enclosed in quotes. The syntax for this parameter is a string. Why is it not enclosed in quotes? In the for loop for New-AzVm the -Name value IS enclosed in quotes. Similarly on the Set-AzVMExtension for loop, the -VName is NOT enclosed in quotes but the syntax for this parameter is also a string. The examples on the https://docs.microsoft.com/ pages for these cmdlets have the values enclosed in quotes. Does this affect the execution of the code one way or the other or is it acceptable to do it either way?

Similar question with the value of the -Location. Is the proper notation "EastUS2" or "East US2" or "East US 2" or does it matter? Should the -Location value be enclosed in quotes or not? Again the location is not enclosed in quotes in the Set-AzVMExtension for loop. Is this possibly affecting the execution of the code to not have the location enclosed in quotes?


0 Votes 0 ·