OneDrive Online Graph API Org Settings

Prasanth J.k 40 Reputation points
2024-05-24T04:37:29.77+00:00

Not getting data of Onedrive while using sharepoint endpoint graph api. Since they are merged already in console. Is there a api to get information on OneDrive? If not, how can we connect or manage unattended script using Sharepoint powershell.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,068 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,767 questions
OneDrive Management
OneDrive Management
OneDrive: A Microsoft file hosting and synchronization service.Management: The act or process of organizing, handling, directing or controlling something.
1,171 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,726 Reputation points Microsoft Vendor
    2024-05-24T06:10:30.1833333+00:00

    Hi @Prasanth J.k,

    You could use credential object to connect sharepoint with graph. Please refer to the following script

    $AppId = 'xxxxx-xxxx-xxxxx'
    $CredentialPath = "C:\temp\$AppId.key"
    $AppCredential = Import-CredentialFile -Path $CredentialPath
    
    $Scope = "https://graph.microsoft.com/.default"
    $Url = "https://login.microsoftonline.com/devmodernworkplace.onmicrosoft.com/oauth2/v2.0/token"
    
    $Body = @{
        client_id = $AppCredential.UserName
        client_secret = $AppCredential.GetNetworkCredential().password
        scope = $Scope
        grant_type = 'client_credentials'
    }
    
    $AuthorizationRequest = Invoke-RestMethod -Uri $Url -Method 'post' -Body $Body
    $AuthorizationRequest
    

    Here is a nice article with details, you could following the steps

    https://sposcripts.com/access-sharepoint-via-graph-api-in-powershell/


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.