Azure not creating VMs via PowerShell

Fisher, Ethan 26 Reputation points
2021-10-17T23:06:12.387+00:00

I am working the tutorial
Load balance Windows virtual machines in Azure to create a highly available application with Azure PowerShell" https://learn.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
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,129 questions
0 comments No comments
{count} votes

Accepted answer
  1. shiva patpi 13,141 Reputation points Microsoft Employee
    2021-10-18T01:12:57.98+00:00

    Hello @Fisher, Ethan ,
    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.


0 additional answers

Sort by: Most helpful