From 8270fd5a57e687bd68e578a505e314fe05fcee68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Wed, 24 Jun 2026 11:57:51 +0200 Subject: [PATCH] Expose Autopilot association metadata --- GraphEssentials.psd1 | 2 +- Public/Get-MyDevice.ps1 | 8 +++++++- Public/Get-MyDeviceIntune.ps1 | 8 +++++++- Tests/Get-MyDeviceIntune.Tests.ps1 | 6 ++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/GraphEssentials.psd1 b/GraphEssentials.psd1 index a61ef44..3e1c73f 100644 --- a/GraphEssentials.psd1 +++ b/GraphEssentials.psd1 @@ -8,7 +8,7 @@ Description = 'GraphEssentials is a PowerShell module that helps with Office 365 / Azure AD using mostly Graph' FunctionsToExport = @('Disable-MyDevice', 'Get-MgToken', 'Get-MyApp', 'Get-MyAppCredentials', 'Get-MyConditionalAccess', 'Get-MyDefenderDeploymentKey', 'Get-MyDefenderHealthIssues', 'Get-MyDefenderSecureScore', 'Get-MyDefenderSecureScoreProfile', 'Get-MyDefenderSensor', 'Get-MyDefenderSummary', 'Get-MyDevice', 'Get-MyDeviceIntune', 'Get-MyGuest', 'Get-MyLicense', 'Get-MyRole', 'Get-MyRoleHistory', 'Get-MyRoleUsers', 'Get-MyTeam', 'Get-MyTenantName', 'Get-MyUsageReports', 'Get-MyUser', 'Get-MyUserAuthentication', 'Invoke-MyDeviceRetire', 'Invoke-MyGraphEssentials', 'Invoke-MyGraphUsageReports', 'New-MyApp', 'New-MyAppCredentials', 'Register-FIDO2Key', 'Remove-MyAppCredentials', 'Remove-MyAutopilotDevice', 'Remove-MyDevice', 'Remove-MyDeviceIntuneRecord', 'Send-MyApp', 'Show-MyApp', 'Show-MyConditionalAccess', 'Show-MyDefender', 'Show-MyRole', 'Show-MyUserAuthentication') GUID = '75ef812f-6d8e-4898-81bb-8029e0560ef3' - ModuleVersion = '0.0.58' + ModuleVersion = '0.0.59' PowerShellVersion = '5.1' PrivateData = @{ PSData = @{ diff --git a/Public/Get-MyDevice.ps1 b/Public/Get-MyDevice.ps1 index 2dc79fe..a2a2ac1 100644 --- a/Public/Get-MyDevice.ps1 +++ b/Public/Get-MyDevice.ps1 @@ -111,6 +111,8 @@ } $AutopilotDevice = Find-GraphEssentialsAutopilotDevice -Lookup $AutopilotLookup -AzureAdDeviceId $Device.DeviceId + $AutopilotLastContacted = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('LastContactedDateTime', 'lastContactedDateTime') } else { $null } + $AutopilotLastContactedDays = if ($AutopilotLastContacted) { [math]::Floor((New-TimeSpan -Start $AutopilotLastContacted -End $Today).TotalDays) } else { $null } [PSCustomObject] @{ Name = $Device.DisplayName @@ -142,10 +144,14 @@ AutopilotInventoryLoaded = if ($IncludeAutopilotInventory) { [bool] $AutopilotLookup.InventoryLoaded } else { $false } AutopilotOnboarded = if ($IncludeAutopilotInventory -and $AutopilotLookup.InventoryLoaded) { [bool] $AutopilotDevice } else { $null } AutopilotDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('Id', 'id') } else { $null } + AutopilotManagedDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('ManagedDeviceId', 'managedDeviceId') } else { $null } + AutopilotAzureAdDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('AzureAdDeviceId', 'azureAdDeviceId', 'AzureActiveDirectoryDeviceId', 'azureActiveDirectoryDeviceId') } else { $null } + AutopilotResourceName = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('ResourceName', 'resourceName', 'DisplayName', 'displayName') } else { $null } AutopilotGroupTag = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('GroupTag', 'groupTag') } else { $null } AutopilotSerialNumber = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('SerialNumber', 'serialNumber') } else { $null } AutopilotEnrollmentState = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('EnrollmentState', 'enrollmentState') } else { $null } - AutopilotLastContacted = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('LastContactedDateTime', 'lastContactedDateTime') } else { $null } + AutopilotLastContacted = $AutopilotLastContacted + AutopilotLastContactedDays = $AutopilotLastContactedDays AutopilotUserPrincipalName = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('UserPrincipalName', 'userPrincipalName') } else { $null } } } diff --git a/Public/Get-MyDeviceIntune.ps1 b/Public/Get-MyDeviceIntune.ps1 index a46659a..144a015 100644 --- a/Public/Get-MyDeviceIntune.ps1 +++ b/Public/Get-MyDeviceIntune.ps1 @@ -135,6 +135,8 @@ } $AutopilotDevice = Find-GraphEssentialsAutopilotDevice -Lookup $AutopilotLookup -ManagedDeviceId $DeviceI.Id -AzureAdDeviceId $DeviceI.AzureAdDeviceId -SerialNumber $DeviceI.SerialNumber + $AutopilotLastContacted = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('LastContactedDateTime', 'lastContactedDateTime') } else { $null } + $AutopilotLastContactedDays = if ($AutopilotLastContacted) { [math]::Floor((New-TimeSpan -Start $AutopilotLastContacted -End $Today).TotalDays) } else { $null } $DetailedInventoryLoaded = $false $ActivationLockBypassCode = $null @@ -225,10 +227,14 @@ AutopilotInventoryLoaded = if ($IncludeAutopilotInventory) { [bool] $AutopilotLookup.InventoryLoaded } else { $false } AutopilotOnboarded = if ($IncludeAutopilotInventory -and $AutopilotLookup.InventoryLoaded) { [bool] $AutopilotDevice } else { $null } AutopilotDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('Id', 'id') } else { $null } + AutopilotManagedDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('ManagedDeviceId', 'managedDeviceId') } else { $null } + AutopilotAzureAdDeviceId = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('AzureAdDeviceId', 'azureAdDeviceId', 'AzureActiveDirectoryDeviceId', 'azureActiveDirectoryDeviceId') } else { $null } + AutopilotResourceName = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('ResourceName', 'resourceName', 'DisplayName', 'displayName') } else { $null } AutopilotGroupTag = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('GroupTag', 'groupTag') } else { $null } AutopilotSerialNumber = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('SerialNumber', 'serialNumber') } else { $null } AutopilotEnrollmentState = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('EnrollmentState', 'enrollmentState') } else { $null } - AutopilotLastContacted = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('LastContactedDateTime', 'lastContactedDateTime') } else { $null } + AutopilotLastContacted = $AutopilotLastContacted + AutopilotLastContactedDays = $AutopilotLastContactedDays AutopilotUserPrincipalName = if ($AutopilotDevice) { Get-GraphEssentialsObjectProperty -InputObject $AutopilotDevice -Name @('UserPrincipalName', 'userPrincipalName') } else { $null } #AdditionalProperties = $DeviceI.AdditionalProperties # : {} } diff --git a/Tests/Get-MyDeviceIntune.Tests.ps1 b/Tests/Get-MyDeviceIntune.Tests.ps1 index 7899f31..57b4d47 100644 --- a/Tests/Get-MyDeviceIntune.Tests.ps1 +++ b/Tests/Get-MyDeviceIntune.Tests.ps1 @@ -113,6 +113,7 @@ Describe 'Get-MyDeviceIntune' { ManagedDeviceId = 'managed-1' AzureActiveDirectoryDeviceId = 'device-1' SerialNumber = 'serial-1' + ResourceName = 'serial-1' GroupTag = 'pilot' EnrollmentState = 'enrolled' LastContactedDateTime = (Get-Date).AddDays(-5) @@ -127,8 +128,13 @@ Describe 'Get-MyDeviceIntune' { $devices[0].AutopilotInventoryLoaded | Should -BeTrue $devices[0].AutopilotOnboarded | Should -BeTrue $devices[0].AutopilotDeviceId | Should -Be 'autopilot-1' + $devices[0].AutopilotManagedDeviceId | Should -Be 'managed-1' + $devices[0].AutopilotAzureAdDeviceId | Should -Be 'device-1' + $devices[0].AutopilotResourceName | Should -Be 'serial-1' $devices[0].AutopilotGroupTag | Should -Be 'pilot' + $devices[0].AutopilotSerialNumber | Should -Be 'serial-1' $devices[0].AutopilotEnrollmentState | Should -Be 'enrolled' + $devices[0].AutopilotLastContactedDays | Should -BeGreaterOrEqual 4 } It 'does not match Autopilot devices by duplicate serial number alone' {