From 0e6956be88ba320162cf3b179f10c7ebf144c2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Nikoli=C4=87?= Date: Wed, 11 Feb 2026 18:31:37 +0000 Subject: [PATCH] Fix API version condition for Microsoft Graph MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Intent:** When the `-Graph` switch is used, this line is meant to validate `$ApiVersion` and default it to `'v1.0'` if the caller didn't pass a valid Microsoft Graph API version (`'v1.0'` or `'beta'`). Since the parameter defaults to `'2024-11-01'` (an ARM version), this normalization is needed for Graph calls. **⚠️ Bug:** The condition uses `-or` but should use `-and`. As written, the expression **always evaluates to `$true`**: | `$ApiVersion` value | `-ne 'v1.0'` | `-ne 'beta'` | `-or` result | |---|---|---|---| | `'v1.0'` | `$false` | `$true` | **`$true`** ✗ | | `'beta'` | `$true` | `$false` | **`$true`** ✗ | | `'2024-11-01'` | `$true` | `$true` | **`$true`** ✓ | This means `$ApiVersion` is **always** overwritten to `'v1.0'`, making it impossible to use `'beta'`. **Fix:** Replace `-or` with `-and`: ```powershell if ($ApiVersion -ne 'v1.0' -and $ApiVersion -ne 'beta') { $ApiVersion = 'v1.0' } ``` This correctly reads: *"if the version is **neither** `'v1.0'` **nor** `'beta'`, default to `'v1.0'`."* --- powershell/public/core/Invoke-MtAzureRequest.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powershell/public/core/Invoke-MtAzureRequest.ps1 b/powershell/public/core/Invoke-MtAzureRequest.ps1 index bbcbcf3b9..7930b24e1 100644 --- a/powershell/public/core/Invoke-MtAzureRequest.ps1 +++ b/powershell/public/core/Invoke-MtAzureRequest.ps1 @@ -62,7 +62,7 @@ function Invoke-MtAzureRequest { if ($Graph) { $baseUri = $((Get-AzContext).Environment.ExtendedProperties.MicrosoftGraphUrl) if ( -not $baseUri) { $baseUri = 'https://graph.microsoft.com' } - if ($ApiVersion -ne 'v1.0' -or $ApiVersion -ne 'beta') { $ApiVersion = 'v1.0' } + if ($ApiVersion -ne 'v1.0' -and $ApiVersion -ne 'beta') { $ApiVersion = 'v1.0' } $uriQueryEndpoint = New-Object System.UriBuilder -ArgumentList ([IO.Path]::Combine($baseUri, $ApiVersion, $RelativeUri)) @@ -94,4 +94,4 @@ function Invoke-MtAzureRequest { Write-Verbose ($params | ConvertTo-Json -Depth 3) $result = Invoke-AzRest @params return $result.Content | ConvertFrom-Json -} \ No newline at end of file +}