Skip to content

Conversation

@alexandair
Copy link
Contributor

Description

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:

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'."

Contribution Checklist

Before submitting this PR, please confirm you have completed the following:

  • 📖 Read the guidelines for contributing to this repository.
  • 🧪 Ensure the build and unit tests pass by running /powershell/tests/pester.ps1 on your local system.

**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'`."*
Copilot AI review requested due to automatic review settings February 11, 2026 18:38
@alexandair alexandair requested a review from a team as a code owner February 11, 2026 18:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a logic bug in Invoke-MtAzureRequest when the -Graph switch is used, ensuring the Microsoft Graph API version is only defaulted to v1.0 when the caller did not explicitly request a valid Graph version (v1.0 or beta).

Changes:

  • Corrected the Graph API version normalization condition from -or to -and so beta is no longer always overridden.
  • Minor diff-only formatting/line alignment at the end of the file (no functional impact).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SamErde SamErde merged commit 8ea3a31 into maester365:main Feb 11, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants