使用 Add-AzureVhd 时出现错误 400

Error 400 when using Add-AzureVhd

我尝试上传一个vhd到azure(固定大小30GB),但是上传结束后总是报错

在此之前,我导入了我的发布设置文件,我将我的订阅设为默认,并将默认存储设置为 vhds

Add-AzureVhd -Destination "https://*****.blob.core.windows.net/vhds/vm.vhd" -LocalFilePath "C:\Users\****\Desktop\vm.vhd" MD5 hash is being calculated for the file C:\Users\****\Desktop\vm.vhd. MD5 hash calculation is completed. Elapsed time for the operation: 00:02:59 Creating new page blob of size 32212255232... Add-AzureVhd : The remote server returned an error: (400) Bad Request. At line:1 char:1 + Add-AzureVhd -Destination "https://*****.blob.core.windows.net/vhds ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-AzureVhd], StorageException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Storage.StorageException,Microsoft.WindowsAzure.Commands.ServiceM anagement.StorageServices.AddAzureVhdCommand

您知道如何解决这个问题吗?

这里有一些解决问题的方法。我刚刚尝试了你同样的挑战没有问题。

首先,我认为你的错误是在上传之前弹出的。因为整个过程是这样的。似乎在尝试创建新 blob 后立即弹出您的错误。之后是一个漫长的过程,其中检测到 VHD 的空白空间。

PS C:\Users\pkirch> Add-AzureVhd -LocalFilePath 'C:\Hyper-V\Virtual Hard Disks\test30gb.vhd' -Destination "https://webdavsvr.blob.core.windows.net/vhds/test30gb.vhd"
MD5 hash is being calculated for the file  C:\Hyper-V\Virtual Hard Disks\test30gb.vhd.
MD5 hash calculation is completed.
Elapsed time for the operation: 00:02:58
Creating new page blob of size 32212255232...
Detecting the empty data blocks in the local file.
Detecting the empty data blocks completed.
Elapsed time for upload: 00:00:00

LocalFilePath                              DestinationUri                                           
-------------                              --------------                                           
C:\Hyper-V\Virtual Hard Disks\test30gb.vhd https://webdavsvr.blob.core.windows.net/vhds/test30gb.vhd

前段时间我发了一篇script to upload a VHD on GitHub Gist。如果您没有错过任何一步,请查看。主要是:

  1. 正在设置当前订阅。
  2. (如果你已经有一个存储空间 帐户和一个容器,您不必创建一个新的)
  3. 正在为当前订阅设置当前存储帐户。

    # Settings

    $SubscriptionName = "Azure MSDN - pkirchner"
    $StorageAccountName = "pkteststorageaccount"
    $Container = "vhds"
    $LocalVhd = "C:\Users\pkirch\fixedvhd20mb.vhd"

    # Select my Microsoft Azure Subscription.
    Select-AzureSubscription -SubscriptionName $SubscriptionName

    # Create new storage account.
    New-AzureStorageAccount -Location "West Europe" -StorageAccountName $StorageAccountName -Type Standard_LRS

    # Create container for VHDs.
    $StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName

    New-AzureStorageContext -StorageAccountKey $StorageAccountKey.Primary -StorageAccountName $StorageAccountName | `
    New-AzureStorageContainer -Name $Container -Permission Off

    # Add-AzureVhd needs the CurrentStorageAccountName to be set.
    Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $StorageAccountName

    # Build destination path automatically.
    $NewContainer = Get-AzureStorageContainer -Name $Container
    $VhdFile = Split-Path -Path $LocalVhd -Leaf
    $Destination = $NewContainer.CloudBlobContainer.Uri.AbsoluteUri + "/" +  $VhdFile

    # Upload VHD
    Add-AzureVhd -Destination $Destination -LocalFilePath $LocalVhd

第二,如果您没有遗漏任何步骤,我会尝试使用 Fiddler 查找错误。将 Fiddler 与 PowerShell for Azure 结合使用并不简单。这是 blog post 操作方法。