Forum Discussion

LeonPavesic's avatar
LeonPavesic
Silver Contributor
Mar 18, 2024
Solved

PowerShell - GraphAPI - OneDrive Shared files - Error

Hello everybody, for changing the UPN for some number of users I need to export all the shared files in OneDrive for all users in the tenant. I have found an excellent script by the MVP Vasil M...
  • LainRobertson's avatar
    Mar 20, 2024

    LeonPavesic 

     

    As an afterthought, the Renew-Token function is flawed and can lead to the unexpected outcome of re-trying a query despite the token renewal having failed.

     

    Given how the function has been used on line 237 and impacts lines 239 to 241, it's quite possible that the token renewal has failed, yet because the $authHeader variable has at no stage been removed, that the wrong conclusion is reached on line 239 - where the pre-existing header featuring the since-expired token remains in existence.

     

    The "easiest" solution to this is to remove the $authHeader variable on the first line of the Renew-Token function using the Remove-Variable commandlet. That way, only a successful renewal will result in its recreation later in the function.

     

    You'd then have to check for any knock-on impacts, but at least in the specific case of lines 239 to 241, the outcome would be fine, and indeed, expected.

     

    As the script is now though, line 239 will always evaluate to $false, meaning line 241 will always execute, even in the token renewal failure scenario.

     

    Cheers,

    Lain

Resources