Skip to content

Issue 436 Intune Last Seen Not Updating

Ed Mozley edited this page Nov 24, 2026 · 1 revision

πŸ’» #436 Last seen stopped updating for Intune devices after the first sync

GitHub #436, reported by @BeardedWookie Β· Assets, Intune Β· fixed after 5.10.1 (#3181)

What you saw

With the Intune sync switched on, an asset's Last seen was filled in the first time the sync brought the device in - and then never changed again. Intune showed the device checking in that morning; FreeITSM still showed the day it was first synced, and once that was more than seven days ago the date turned amber and the machine was counted as not seen on the Watchtower dashboard.

What was wrong

The sync does two things with each device. It stores what Intune says about it - including the last check-in, Intune's lastSyncDateTime - in intune_devices, and it links that row to an asset. The check-in was copied onto the asset in exactly one place: when the sync had to create a new asset for a device it could not match.

// includes/intune.php, intuneLinkDevicesToAssets() - step 2, unlinked devices only
$assetId = AssetsService::createDiscoveredAsset($conn, $ctx, [
    'hostname'  => $hostname,
    ...
    'last_seen' => $row['last_sync_datetime'],   // the only place the check-in reached the asset
], $companyId, 'Intune', $res['hostname_reused']);

Every later sync updated intune_devices.last_sync_datetime faithfully, but a device that was already linked never went through that code again, so nothing carried the new check-in across to assets.last_seen.

Two cases, not one

  • A device the sync created an asset for got its check-in once, on that day, and kept it for ever. This is what was reported.
  • A device the sync matched to an asset that already existed (by serial number or host name - an asset added by hand, or imported, before Intune was connected) never got a Last seen from Intune at all. If the inventory agent was not installed on it either, it read Never reported.

Is it anywhere else?

Every other source that writes assets.last_seen was checked:

Source Updates Last seen on every report?
System information agent (api/external/system-info/submit/index.php) βœ… yes - on every submission, new asset or matched
Software inventory agent (api/external/software-inventory/submit/index.php) βœ… yes - the same
Proxmox and vCloud syncs they do not write assets at all (they keep their own last_seen_datetime on the virtual estate)
Asset merge (includes/services/asset_merge.php) keeps the later of the two dates - correct
Intune sync ❌ only when it created the asset - the bug

So it was the Intune sync alone.

The fix

A new step, intuneRefreshLastSeen(), runs at the end of every sync's linking stage. It moves each linked asset's Last seen up to its device's latest check-in:

// includes/intune.php
function intuneRefreshLastSeen(PDO $conn): int {
    $st = $conn->prepare(
        "UPDATE assets a
           JOIN (SELECT asset_id, MAX(last_sync_datetime) AS checked_in
                   FROM intune_devices
                  WHERE asset_id IS NOT NULL AND last_sync_datetime IS NOT NULL
                    AND last_sync_datetime <= DATE_ADD(UTC_TIMESTAMP(), INTERVAL 1 DAY)
               GROUP BY asset_id) d ON d.asset_id = a.id
            SET a.last_seen = d.checked_in
          WHERE a.last_seen IS NULL OR a.last_seen < d.checked_in"
    );
    $st->execute();
    return $st->rowCount();
}

Three rules are built into that statement:

  • Only forward. The inventory agents write Last seen too, and the agent may well have reported more recently than Intune's last check-in. An older check-in never pulls a newer date back.
  • The latest device wins. If two Intune devices are linked to one asset (a re-enrolment, say), the later check-in is used.
  • A date in the future is ignored. A device with a wrong clock would otherwise mark its asset as seen for months to come.

A retired asset is included on purpose: Assets already promises that a retired machine Intune still sees keeps its record unchanged except Last seen, so it shows up as still on the network. That promise is now true for Intune as well as the agents.

The sync log says how many assets it moved (last_seen_updated=N on the "linking done" line).

What this means for you

Nothing to switch on. At the next Intune sync, every linked asset's Last seen jumps to its device's real last check-in, and machines that are checking in drop out of the Watchtower not seen count. Anything still amber after that sync really has not checked in to Intune - or reported through an agent - for over a week.

πŸ“ Files

File Change
πŸ”΅ includes/intune.php intuneRefreshLastSeen(), called as the last step of intuneLinkDevicesToAssets(); the count in the sync log
🟒 tests/intune-last-seen.php new regression test

βœ… How it was proved

tests/intune-last-seen.php (11 checks, inside a transaction that is always rolled back):

  • Positive control: an asset last seen ten days ago whose device checked in an hour ago moves to an hour ago - the reported bug.
  • An asset with no Last seen gets one; a newer agent report is not pulled back to an older check-in; two devices give the later check-in; a check-in 30 days in the future is ignored; a device that never checked in, or one linked to no asset, changes nothing; a second run changes nothing more.
  • Through the sync's real linking step (intuneLinkDevicesToAssets()), not just the new function on its own.

Control: the same ten-days-old asset run through the old includes/intune.php linking step - its device checked in an hour before, and the asset still read ten days ago.

Related

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally