Question

I've successfully created a VM in Azure and used the following to export its settings and then remove the VM and Service:

export-azurevm -servicename "testautomation" -name "testautomation" -path "C:\azurestates\testautomation.xml"

remove-azurevm -servicename "testautomation" -name "testautomation"

However, when I attempt to recreate the VM, I get the following:

PS C:> import-azurevm -path "C:\azurestates\testautomation.xml" | new-azurevm -servicename 'testautomation' -location "east us"

new-azurevm : The remote server returned an unexpected response: (400) Bad Request. At line:1 char:60 + import-azurevm -path "C:\azurestates\testautomation.xml" | new-azurevm -servicen ... + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzureVM], ProtocolException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand

This seems as if it should be really simple and I'm not quite sure where I'm going wrong. Googling this error has pointed me to several changes when using New-AzureVMConfig, but I'm unsure how to proceed since I'm not using that. Any assistance would be greatly appreciated.

Was it helpful?

Solution 2

The problem was with my Set-AzureSubscription commandlet. I capitalized the storage account in that command and it was ultimately causing the issue I was experiencing here. It took me a while to track it down because I didn't think to examine that command closely since everything else I was doing via powershell was working. Many thanks for your assistance and the code to track down the inner exception (which was the linchpin to solving the issue)!

OTHER TIPS

You can get more details about what went wrong by taking a look at the inner exception:

PS C:\> $sr = new-object System.IO.StreamReader($Error[0].Exception.InnerException.Response.GetResponseStream())
PS C:\> $txt = $sr.ReadToEnd()
PS C:\> $txt
PS C:\> $sr.Close()

The third command should print out a more detailed error message about what was wrong with the New-AzureVM call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top