Cannot create VM

Anonymous
2022-08-11T20:12:42.667+00:00

Not able to cannot create VM using PowerShell commands. Getting an error:

ERROR: New-AzVM : Subscription db9d3b30-6d46-4e22-9170-87b069eeaf08 was not found.

230603-image.png

Below are the required details and script commands used to create the VM:

Subscription: db9d3b30-6d46-4e22-9170-87b069eeaf08 [PROD-SUB]

Region: East US 2

Commands used to create the Windows VM in PowerShell:

$PIP = New-AzPublicIpAddress -Name windows-jumpbox-pip -Location eastus2 -AllocationMethod Dynamic -ResourceGroupName mgmt-nodes-eastus2
$NIC = New-AzNetworkInterface -Name windows-jumpbox-nic -ResourceGroupName mgmt-nodes-eastus2 -Location eastus2 -SubnetId "/subscriptions/db9d3b30-6d46-4e22-9170-87b069eeaf08/resourceGroups/mgmt-nodes-eastus2/providers/Microsoft.Network/virtualNetworks/idrac-nodes-eastus2/subnets/idrac-vm-subnet" -PublicIpAddressId $PIP.Id
$securePassword = ConvertTo-SecureString '***************' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ("azureuser", $securePassword);
$VirtualMachine = New-AzVMConfig -VMName windows-jumpbox -VMSize Standard_D2s_v3
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName "windows-jumpbox" -Credential $Credential -ProvisionVMAgent True
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName 'MicrosoftWindowsDesktop' -Offer "Windows-10" -Sku "win10-21h2-ent-g2" -Version "latest"
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id

New-AzVM -ResourceGroupName "mgmt-nodes-eastus2" -Location eastus2 -VM $VirtualMachine

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,585 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Mohammed Altamash Khan 2,086 Reputation points
    2022-08-11T20:33:18.59+00:00

    Hi

    Kindly review your subscription ID in your azure portal .

    Also refer this : https://www.youtube.com/watch?v=wJqdXjpKQII

    ------------If you find this helpful , Please accept the answer --------------

    0 comments No comments

  2. srbhatta-MSFT 8,551 Reputation points Microsoft Employee
    2022-08-26T06:24:03.107+00:00

    Hello @alex ,
    Thanks for reaching out.
    Please check which subscription you have access to by using the below command.

    Get-AzSubscription  
    

    The, using the below command, set your active subscription for this session using the below command.

    Set-AzContext -SubscriptionId "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"  
    

    Hope this helps. Feel free to revert back if you have any questions,

    -----------------

    If you find the above information helpful, kindly accept as answer or upvote to increase the relevancy of this post.

    0 comments No comments