I am trying to develop a process which can download the files from ODB which are shared by user using the "Share" feature in office application like word, excel and powerpoint.
When a file is shared an email is sent to the person with whom the file is shared. The Url in the email is
The code i am using is
$Norma1izedURL = [System.Web.HttpUtility]::UrlDecode($Source)
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Norma1izedURL)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText = "u!" + $EncodedText.TrimEnd('=').Replace('/','_').Replace('+','-')
$SharedDriveItem = "https://graph.microsoft.com/v1.0/shares/" + $EncodedText + "/driveitem"
$DownloadURL = Invoke-Restmethod -method Get -Headers @{'Authorization' = "Bearer $($Authresult.accesstoken)"} -Uri $SharedDriveItem
This fails with the error Invoke-Restmethod : The remote server returned an error: (400) Bad Request. At line:1 char:1 + Invoke-Restmethod -method Get -Headers @{'Authorization' = "Bearer $( ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I am using an azure app with application permissions File.Read.All
i have searched a lot but could not find anything with similar issue... any pointers would be of great help