Description
`Add-AzVhd` throws a terminating error when uploading a VHD in an Azure Government environment, even though the upload completes successfully. The underlying storage backend returns HTTP `200 OK` for the upload operation; the cmdlet appears to expect `201 Created` and treats the `200` response as a failure.
This is consistent with the Disks - Grant Access REST API spec, which documents `200 OK` as a valid synchronous-success response — so Azure Gov is behaving correctly. The cmdlet's SDK layer does not appear to handle the `200` path.
Expected behavior: Upload completes without error.
Actual behavior: Exception thrown despite successful upload; blob is present and correctly sized in storage.
Issue Script & Debug Output
$DebugPreference = 'Continue'
Add-AzVhd `
-ResourceGroupName "<resource-group>" `
-Destination "https://<storage>.blob.core.usgovcloudapi.net/vhds/<name>.vhd" `
-LocalFilePath "<path-to-local.vhd>" `
-ErrorAction Stop
Run against an Azure Government subscription. Upload will throw an exception while the blob is successfully created in storage.
Environment Data
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module Versions
Az.Accounts 4.0.0
Az.Compute 9.0.0
Az.Storage 8.0.0
Error Output
Not available — error was not captured at time of discovery.
Workaround
Wrap the call in `try/catch` and verify blob existence and size before re-throwing:
try {
Add-AzVhd -ResourceGroupName $rg -Destination $dest -LocalFilePath $local -ErrorAction Stop
} catch {
$blob = Get-AzStorageBlob -Container $container -Context $ctx | Where-Object { $_.Name -eq $blobName }
if (-not $blob -or $blob.Length -ne (Get-Item $local).Length) { throw }
Write-Host "Upload completed (Add-AzVhd returned non-standard status in Azure Gov)."
}
Description
`Add-AzVhd` throws a terminating error when uploading a VHD in an Azure Government environment, even though the upload completes successfully. The underlying storage backend returns HTTP `200 OK` for the upload operation; the cmdlet appears to expect `201 Created` and treats the `200` response as a failure.
This is consistent with the Disks - Grant Access REST API spec, which documents `200 OK` as a valid synchronous-success response — so Azure Gov is behaving correctly. The cmdlet's SDK layer does not appear to handle the `200` path.
Expected behavior: Upload completes without error.
Actual behavior: Exception thrown despite successful upload; blob is present and correctly sized in storage.
Issue Script & Debug Output
Environment Data
Module Versions
Error Output
Not available — error was not captured at time of discovery.
Workaround
Wrap the call in `try/catch` and verify blob existence and size before re-throwing: