Skip to content

Code Quality: Hardcoded Graph URLs break USGov, stale parameter docs, missing error handling #115

@ugurkocde

Description

@ugurkocde

Summary

Weekly code quality review found several issues across security, error handling, and code quality categories.


Security

1. Hardcoded Graph API URLs in Get-AssignmentFailures bypass environment configuration

File: IntuneAssignmentChecker.ps1, lines 1509, 1513, 1541, 1545

The Get-AssignmentFailures function uses hardcoded https://graph.microsoft.com URLs instead of $script:GraphEndpoint. This completely breaks the "Show Failed Assignments" feature (option 11) for USGov and USGovDoD tenants.

Current code (line 1509):

$configPoliciesUri = "https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations"

Suggested fix:

$configPoliciesUri = "$script:GraphEndpoint/beta/deviceManagement/deviceConfigurations"

All four hardcoded URLs in this function (lines 1509, 1513, 1541, 1545) need the same treatment. The commented-out app failure block (lines 1468, 1473) also has the same issue and should be fixed before re-enabling.


Error Handling

2. Get-GroupMemberships lacks try/catch around API call

File: IntuneAssignmentChecker.ps1, line 1278

This function calls Invoke-MgGraphRequest without any error handling. If the API call fails (e.g., permission denied, network error), an unhandled exception will surface to the user.

Current code:

function Get-GroupMemberships {
    param (
        [Parameter(Mandatory = $true)]
        [string]$ObjectId,
        [Parameter(Mandatory = $true)]
        [ValidateSet("User", "Device")]
        [string]$ObjectType
    )

    $uri = "$GraphEndpoint/v1.0/$($ObjectType.ToLower())s/$ObjectId/transitiveMemberOf?`$select=id,displayName"
    $response = Invoke-MgGraphRequest -Uri $uri -Method Get

    return $response.value
}

Suggested fix: Wrap in try/catch consistent with other functions like Get-TransitiveGroupMembership (line 1283) which handles the same pattern correctly.


Code Quality

3. Ghost ShowAdminTemplates parameter in help documentation

File: IntuneAssignmentChecker.ps1, line 247

The .PARAMETER ShowAdminTemplates entry exists in the comment-based help, but this parameter was removed from the param() block in v3.4.0. This misleads users reading Get-Help.

Fix: Remove the .PARAMETER ShowAdminTemplates block (line 247-248).

4. PSScriptInfo RELEASENOTES missing v3.10.0 entry

File: IntuneAssignmentChecker.ps1, lines 4-12

The .VERSION is 3.10.0 but .RELEASENOTES starts at Version 3.9.1. There is no release notes entry for 3.10.0, which describes what changed in the current version (the _v3 filename fix and auto-update URL correction).

Fix: Add a Version 3.10.0: block at the top of .RELEASENOTES describing the filename and URL fixes.


Priority

  1. Hardcoded URLs - Functional breakage for USGov/USGovDoD tenants
  2. Missing error handling - Unhandled exceptions in group membership lookup
  3. Stale docs - User confusion from removed parameter
  4. Missing release notes - Minor but affects PSGallery metadata

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions