New-AzureVM : BadRequest: The virtual network <foo> does not exist.

Just a quickie. It’s been a long week, and I’ve been trying to get my head around using PowerShell to automate deployments in Azure.

However, I did come across a little glitch in the way that this is supposed to work.

Here’s the syntax I was using:

New-AzureVMConfig -Name $myVMName -InstanceSize $myInstanceSize -ImageName $image.ImageName `
|Add-AzureProvisioningConfig -AdminUserName $myAdminName -Password $myAdminPassword -WindowsDomain -JoinDomain $myDomainFQDN -Domain $myDomainAdminUserDomain -DomainUserName$myDomainAdminUserName -DomainPassword $myDomainAdminPassword -MachineObjectOU $myDomainMachineOU `
|Set-AzureSubnet -SubnetNames $myVLAN `
|Set-AzureStaticVNetIP -IPAddress $myVMIPAddress `
|New-AzureVM -ServiceName $myVMName -Location $myLocation -WaitForBoot -VNetName$myVirtualNetwork

When I got the error message:

VERBOSE: 09:42:11 - Begin Operation: New-AzureVM - Create Deployment with VM TRTestSQLAuto
New-AzureVM : BadRequest: The virtual network SSDevPortal does not exist.
At line:6 char:10
+ |New-AzureVM -ServiceName $myVMName -Location $myLocation -WaitForBoot - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand

Now, the problem here is that when I look at the virtual network in the Admin Preview Portal, I see that it is there with the right name.

Virtual Networks

So, what to do? Just to check that I’d managed to get the spelling right, and there wasn’t a space or something, I exported the network config and looked at the XML:

Get-AzureVNetConfig -ExportToFile "C:\Users\TRushton\Desktop\VNetConfig.xml"

And there it is, buried in the NetworkConfiguration\VirtualNetworkConfiguration\VirtualNetworkSites area, the VirtualNetworkSite in question:

Network Config XML Excerpt

So, the name in the configuration is not the name that's showing in the Virtual Network window. No wonder it's not working...

Correct the code, and away we go. Job done. But no idea why there's a discrepancy.

Advertisements
This entry was posted in SQLServerPedia Syndication and tagged , , , . Bookmark the permalink.

10 Responses to New-AzureVM : BadRequest: The virtual network <foo> does not exist.

  1. HI Thomas,

    You can also get the VNet Name into the using

    Get-AzureVNetSite | Select Name

    which you can then set tot eh variable if needed

    Rob

  2. Andy says:

    Cheers – I’ve been banging my head against the wall for the last hour or so trying to figure this one out!

    • thomasrushton says:

      Hi Andy

      You’re welcome.

      I’ve just had the same problem with another environment… at least I knew where to look to find the solution!

  3. Willem says:

    Nice one, this saved me some grief. This mixed world we have no of classic Azure IaaS and ARM is a pain.

  4. daveberm says:

    Wish I found this 5 hours ago. Thanks. Now why this happened is another story…

  5. Pingback: “BadRequest: The virtual network Public-Azure-East does not exist” the virtual network name displayed in the portal can be wrong #azure #azureclassic – Clustering For Mere Mortals

  6. This worked for me, thanks!

  7. Selvi K says:

    Thank you very much for taking the time out to share this! I’ve spent a few hours trying to figure this out and this post resolved it for me. The Azure portal should at least have a “details” pop-up that gives the full name of the VNet. How non-intuitive! 😦

  8. Mehmet says:

    Thanks! Saved my day.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s