Skip to content

Script is failing in large tenant due to expired token #80

@tournpa1

Description

@tournpa1

Hi,

I'm trying to run the Intune documentation script in a large tenant infrastructure but experiencing one issue due to expired Token.

I have seen from the release note that a new feature have been added in that regards within 3.3.1 23.3.2025

  • Add Token Refresh for long running collections (big tenants)

We have our own app registration hosted in our tenant and connecting via certificate as following

$tenantId = "myteantID"
$clientId = "AppClientID"
$certThumbprint = "certThumbprint"

$certificate = Get-Item -Path "Cert:\CurrentUser\my$certThumbprint"
$token = Get-MsalToken -ClientId $clientId -TenantId $tenantId -ClientCertificate $certificate -Scope "https://graph.microsoft.com/.default"

Connect-M365Doc -token $token

The connection is successful, and script is working if I collect limited info.

$doc = Get-M365Doc -Components Intune -IncludeSections MdmAppleConfiguration

but if I try to collect several info the script will stop after one hour due to expired token

$doc = Get-M365Doc -Components Intune -IncludeSections MdmAppleConfiguration,MdmCompliancePolicy,MdmConfigurationProfile,MdmDeviceAssignmentFilter,MdmEnrollmentConfiguration

Not sure how I can enforce such token to NOT expire in my authentication flow ?

I tried using "-ForceRefresh" as following but this keeps expiring

$token = Get-MsalToken -ClientId $clientId -TenantId $tenantId -ClientCertificate $certificate -Scope "https://graph.microsoft.com/.default" -ForceRefresh

Any other command I should run to prevent the token to expire ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions