(400)使用New-AzureVM命令行开关时出现错误请求

时间:2013-07-26 17:25:43

标签: azure azure-powershell

我在Azure中成功创建了一个虚拟机,并使用以下方法导出其设置,然后删除虚拟机和服务:

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

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

但是,当我尝试重新创建VM时,我得到以下内容:

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

这似乎应该非常简单,我不太确定我哪里出错了。谷歌搜索这个错误指向我使用New-AzureVMConfig时的几个更改,但我不确定如何继续,因为我没有使用它。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:4)

通过查看内部异常,您可以获得有关出错的更多详细信息:

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()

第三个命令应打印出有关New-AzureVM调用出错的更详细的错误消息。

答案 1 :(得分:2)

问题在于我的Set-AzureSubscription命令行开关。我在该命令中将存储帐户大写,这最终导致了我在这里遇到的问题。我花了一段时间来追踪它,因为我没有想到要仔细检查这个命令,因为我通过powershell做的其他事情都在起作用。非常感谢您的帮助以及追踪内部异常的代码(这是解决问题的关键)!