- Thread Author
- #1
- Joined
- Jul 4, 2015
- Messages
- 8,970
- Joined
- Jul 22, 2005
- Messages
- 8,977
Hey try this, I haven't fully tested it, but yes it needs to be a shareable link:
Its going to output everything as .xlsx so be prepared to change the script if you need to change the filename. It can only do one Gdrive URL at a home at the moment. Feel free to use this script or modify as needed.
Save as whatever.ps1 and invoke from PowerShell with ./whatever.ps1
Remember: Set-ExecutionPolicy unrestricted and then turn it back on when done (for security reasons unless you're comfortable with it off)
Code:
# Prompt the user for the Google Drive file ID or URL
$idOrUrl = Read-Host "Enter the Google Drive file ID or URL"
# Extract the file ID from the URL if necessary
if ($idOrUrl -match "/d/([^/]+)/") {
$fileId = $matches[1]
}
else {
$fileId = $idOrUrl
}
# Construct the download URL
$url = "https://drive.google.com/uc?export=download&id=$fileId"
# Prompt the user for the folder path where they want to save the downloaded file
$folderPath = Read-Host "Enter the folder path where you want to save the file"
# Define the filename with the current date
$filename = "myfile_$(Get-Date -Format 'yyyy-MM-dd').xlsx"
# Combine the folder path and filename
$filePath = Join-Path $folderPath $filename
# Download the file using the Invoke-WebRequest cmdlet
Invoke-WebRequest -Uri $url -OutFile $filePath
Its going to output everything as .xlsx so be prepared to change the script if you need to change the filename. It can only do one Gdrive URL at a home at the moment. Feel free to use this script or modify as needed.
Save as whatever.ps1 and invoke from PowerShell with ./whatever.ps1
Remember: Set-ExecutionPolicy unrestricted and then turn it back on when done (for security reasons unless you're comfortable with it off)
Similar threads
- Replies
- 0
- Views
- 57
- Article
- Replies
- 0
- Views
- 84
- Replies
- 0
- Views
- 20
- Replies
- 0
- Views
- 23
- Replies
- 0
- Views
- 56