Skip to content

Add device lifecycle action helpers#18

Merged
PrzemyslawKlys merged 7 commits into
masterfrom
codex/add-device-lifecycle-actions
Apr 13, 2026
Merged

Add device lifecycle action helpers#18
PrzemyslawKlys merged 7 commits into
masterfrom
codex/add-device-lifecycle-actions

Conversation

@PrzemyslawKlys

Copy link
Copy Markdown
Member

Summary

  • add dedicated GraphEssentials cmdlets for Intune retire and Entra device disable/remove actions
  • enrich device inventory output with stable EntraDeviceObjectId and ManagedDeviceId properties
  • add focused Pester coverage for the new lifecycle helpers

Why

CleanupMonster now has a cloud-device cleanup workflow for AzureAD registered mobile devices. This PR provides the small Graph-facing action layer that workflow depends on, keeping device lifecycle operations reusable and isolated inside GraphEssentials.

Impact

Consumers can now script or reuse these device lifecycle actions directly:

  • Disable-MyDevice
  • Invoke-MyDeviceRetire
  • Remove-MyDevice
  • Remove-MyDeviceIntuneRecord

Validation

  • Invoke-Pester -Path Tests\\MyDeviceLifecycleActions.Tests.ps1 -Output Minimal

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c97389381

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Name = $DeviceI.DeviceName # : EVOMONSTER
Id = $DeviceI.Id # : 83fe122f-c51c-49dc-a0f3-cc11d9e7d045
ManagedDeviceId = $DeviceI.Id
EntraDeviceObjectId = if ($DeviceA) { $DeviceA.Id } else { $null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate EntraDeviceObjectId unconditionally for Intune output

Get-MyDeviceIntune now emits EntraDeviceObjectId from $DeviceA.Id, but $DeviceA is only populated when -Type or -Synchronized is used earlier in the function. On the default path (Get-MyDeviceIntune with no filters), this property is always $null, so piping those objects into Disable-MyDevice or Remove-MyDevice fails during target resolution even though the new docs say these objects are supported.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce50e44490

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Public/Get-MyDeviceIntune.ps1 Outdated
Comment on lines +76 to +78
} catch {
Write-Warning -Message "Get-MyDeviceIntune - Failed to get Azure device identifiers. Error: $($_.Exception.Message)"
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Continue Intune enumeration when Entra lookup fails

The new default path now always calls Get-MgDevice, and this catch block immediately returns from Get-MyDeviceIntune. That means any failure in the Entra lookup step (for example, missing Entra read permissions or a transient Graph error) drops the entire Intune result set even though Get-MgDeviceManagementManagedDevice already succeeded. This is a regression from prior behavior and will break existing callers that only need Intune inventory; the function should degrade gracefully (e.g., keep emitting devices with EntraDeviceObjectId = $null) instead of exiting.

Useful? React with 👍 / 👎.

- keep missing guest sign-in activity distinct from true no-successful-sign-in cases
- restore successful sign-in guest fields used by the external account report

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79dd1dd34d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Public/Get-MyGuest.ps1 Outdated
}

if ($null -ne $Guest.SignInActivity) {
$NeverSignedIn = ($null -eq $LastSignInDaysAgo -and $null -eq $LastNonInteractiveSignInDaysAgo)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include successful-only activity in NeverSignedIn

Get-MyGuest can now classify a user as SignInPattern = 'Successful sign-in only' when only LastSuccessfulSignInDateTime is present, but NeverSignedIn is still computed from interactive/non-interactive fields only. In that case the same record is marked as both having a successful sign-in and NeverSignedIn = $true, which will misclassify active guests in downstream cleanup/reporting logic that filters on NeverSignedIn.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6736b1b84a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Public/Get-MyDeviceIntune.ps1 Outdated
if ($Type -or $Synchronized) {
try {
if (-not $Script:Devices -or $Force -or $Script:DevicesDate -lt (Get-Date).AddMinutes(-$CacheMinutes)) {
$DevicesAzure = Get-MgDevice -All -Property 'deviceId,onPremisesSyncEnabled,trustType' -ErrorAction Stop

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include id in filtered Entra lookup

In the -Type / -Synchronized branch, Get-MgDevice is called with -Property 'deviceId,onPremisesSyncEnabled,trustType', but later the output sets EntraDeviceObjectId from $DeviceA.Id. When this branch runs without a warm $Script:Devices cache, the selected payload can omit Id, so filtered Get-MyDeviceIntune results still lose EntraDeviceObjectId and cannot be piped into Disable-MyDevice/Remove-MyDevice. Adding id to this property list avoids that regression on the filtered path.

Useful? React with 👍 / 👎.

@PrzemyslawKlys PrzemyslawKlys merged commit 37a1556 into master Apr 13, 2026
2 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.

1 participant