Problème d'autorisation lors de la récupération de photos OneDrive personnel avec PowerShell et Microsoft Graph API

Mo7Z 0 Reputation points
2024-05-20T10:32:47.8566667+00:00

Bonjour,

J'essaie d'extraire massivement des liens URL de photos situées dans mon OneDrive personnel à l'aide de PowerShell et de l'API Microsoft Graph. J'ai créé un compte Azure et une application appelée "PowerShell Graph API OneDrive personnel". J'ai activé les autorisations "Files.Read", "Files.Read.All" et "User.Read" pour cette application.

Le type de compte pris en charge est : "Comptes dans un annuaire d'organisation (tout locataire Microsoft Entra ID – Multilocataire) et comptes Microsoft personnels (par exemple, Skype, Xbox)". J'ai également configuré l'URI de redirection (http://localhost).

Cependant, lorsque j'exécute le script PowerShell suivant, je reçois une erreur "Insufficient privileges to complete the operation" (Privilèges insuffisants pour terminer l'opération) :

PowerShell

# 1. Connexion à Microsoft Graph (si ce n'est pas déjà fait)

content_copy

Voici le message d'erreur complet :

Get-MgUser_Get:
Line |
  5 | $user = Get-MgUser -UserId "me"
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | Insufficient privileges to complete the operation.
...

J'ai vérifié que je suis bien connecté au bon compte Microsoft et que les autorisations de l'application sont correctes. Quelqu'un pourrait-il m'aider à résoudre ce problème d'autorisation ?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,418 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,956 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Akhilesh 5,720 Reputation points Microsoft Vendor
    2024-05-23T14:32:06.57+00:00

    Hi @Mo7Z

    Thank you for your post!

    I understand that you are trying to access the Microsoft Graph API using PowerShell, but you are encountering an "Insufficient privileges to complete the operation" error.
    The error is caused by your account not being assigned Azure AD built-in roles such as Global Administrator, Application Administrator or Cloud Application Administrator or not being assigned Azure RBAC roles, such as User Access Administrator or Owner to the scoped subscription.Please take a look to Assign a role to a user and Assign Azure roles using the Azure portal to assign the required roles.
    Also, check what permissions is required to run the query. for more info, please refer sample quires here

    Reference: https://stackoverflow.com/questions/44323560/graph-api-insufficient-privileges-to-complete-the-operation

    Hope this helps. Do let us know if you any further queries.

    Thanks,
    Akhilesh.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.