Azure / Azure/azure-powershell

Add-AzVhd throws exception on successful VHD upload in Azure Government (HTTP 200 OK treated as error)

Open
#29,317 3 comments 0 reactions 0 assignees View on GitHub
act-observability-squad Compute customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### 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](https://learn.microsoft.com/en-us/rest/api/compute/disks/grant-access), 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

```powershell
$DebugPreference = 'Continue'
Add-AzVhd `
-ResourceGroupName "" `
-Destination "https://.blob.core.usgovcloudapi.net/vhds/.vhd" `
-LocalFilePath "" `
-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:

```powershell
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)."
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.