📎 AI Summary:
The thread discusses how to automate downloading a Google Drive Excel file with the current date as its filename on Windows startup. The original poster seeks guidance after unsuccessful searches, and a responder suggests using a shareable link for simplicity. Another user provides a PowerShell script that downloads the file from Google Drive using the file ID or URL, saves it with the current date in the filename, and notes the need to adjust for different filenames or multiple files; security precautions regarding script execution are also mentioned.
The thread discusses how to automate downloading a Google Drive Excel file with the current date as its filename on Windows startup. The original poster seeks guidance after unsuccessful searches, and a responder suggests using a shareable link for simplicity. Another user provides a PowerShell script that downloads the file from Google Drive using the file ID or URL, saves it with the current date in the filename, and notes the need to adjust for different filenames or multiple files; security precautions regarding script execution are also mentioned.
Solution
Hey try this, I haven't fully tested it, but yes it needs to be a shareable link:
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...
- Joined
- Jul 22, 2005
- Messages
- 9,264
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)
Last edited: