microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.53k stars 472 forks source link

O365Group: Get-MgGroup : Your access token has expired. Please renew it before submitting the request. #3949

Open skghq opened 9 months ago

skghq commented 9 months ago

Description of the issue

Command: Export-M365DSCConfiguration -Components @("O365Group") -Credential $Credential -Path $FilePath -FileName $FileName

The first time I ran this was with v1.23.1115.1 and it hung up on exporting [968/3409].

The second time I ran this was with v1.23.1122.1 and it hung up on exporting [894/3411].

I'm re-running this with -Verbose -Debug to see if I can catch it hanging up again.

Many other exports take 3-4+ hours to run and have always completed. O365Group is the only one to hang up, so far, and it has done it twice.

I have also received other errors with O365Group. I have not went through the logs enough to determine if it only impacts this module. Screenshot attached of a third run (v1.23.1115.1.) That export did eventually complete at 19328 seconds (~5.3 hours)

365_dsc_groups 365_dsc_groups2

Microsoft 365 DSC Version

1.23.1122.1

Which workloads are affected

Office 365 Admin

The DSC configuration

Export-M365DSCConfiguration -Components @("O365Group") -Credential $Credential -Path $FilePath -FileName $FileName

Verbose logs showing the problem

|---[894/3411] <<<redacted>>>

.... the process hangs up for hours. I'm re-running this with -Verbose and -Debug parameters and will post output when I catch it hanging up again.

Environment Information + PowerShell Version

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Key   : PSVersion
Value : 5.1.17763.4974
Name  : PSVersion

Key   : PSEdition
Value : Desktop
Name  : PSEdition

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions

Key   : BuildVersion
Value : 10.0.17763.4974
Name  : BuildVersion

Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion
skghq commented 9 months ago

I re-ran O365Group using -Verbose. It is hanging up when the access token expires.

VERBOSE: Dependencies were already successfully validated. VERBOSE: Credential was specified. Connecting via User Principal VERBOSE: Dependencies were already successfully validated. Get-MgGroup : Your access token has expired. Please renew it before submitting the request. Status: 401 (Unauthorized) ErrorCode: Authentication_ExpiredToken Date: 2023-11-25T12:18:52 Headers:

Stack trace: At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1122.1\DSCResources\MSFT_O365Group\MSFT_O365Group.psm1:79 char:9

skghq commented 9 months ago

This is a duplicate of: https://github.com/microsoft/Microsoft365DSC/issues/3531

I closed the original issue as it coincidentally ran successfully once. This ticket has more detail so I did not reopen the old ticket.

andikrueger commented 9 months ago

Thanks for reporting. We've seen this issue with application based authentications before. It's new for Credential based authentication. It looks like we can extend the previous fix for this scenario.

andikrueger commented 9 months ago

Linking #2915 for tracking.

skghq commented 6 months ago

@andikrueger : do you know if this has been fixed for O365Group using application based authentication? I would like to start backing up this resource. I can switch authentication method if needed.