Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bondurantdt/8afcb3a392500695bdc32ddc57d3881a to your computer and use it in GitHub Desktop.
Save bondurantdt/8afcb3a392500695bdc32ddc57d3881a to your computer and use it in GitHub Desktop.
##
#Dependencies: rclone (latest beta, or >1.42 configured to Google Drive and S3), powershell
#Process: Deletes existing items in path, uses rclone to grab all files in a specific folder
#(configured with 'rclone config' command),
#exports those files from Google Drive to PDF, using a couple
#arrays, renames the PDFs to
#the Google Drive File ID, then copies to S3.
##
$dt = Get-Date -format "MMddyyyy"
$log = "FileMover_$dt.log"
$log = "<yourpath>" + $log
Start-Transcript $log
$path = '<yourpath>'
rm $path\*.*
$googlefileid = @()
$filearray = @()
#lsf --format "i" added from here: https://github.com/ncw/rclone/pull/1476
$googlefileid += rclone lsf --format "i" <yourGoogleDrive>:/
rclone copy <yourGoogleDrive>:/ $path --drive-formats pdf --log-file=<yourpath>\sync-$dt.log --log-level INFO
$files = Get-ChildItem -Path:$path -File | ForEach-Object -Process: {
$filearray += $_.Name
}
$filearray 2>&1
for($i = 0; $i -lt $googlefileid.Length; $i++)
{
$oldfile = $filearray[$i]
$newfile = $googlefileid[$i]+".pdf"
Rename-Item -path "$path\$oldfile" -NewName "$path\$newfile" -WhatIf 2>&1
Rename-Item -path "$path\$oldfile" -NewName "$path\$newfile" 2>&1
}
rclone copy $path <s3bucket> --log-file=<yourpath>\sync-$dt.log --log-level INFO
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment