Download file from Gdrive

Copper Contributor

I need to download excel file from my Gdrive account with current date as filename and save it at specific folder when computer starts.

I tried from internet but could not succeed. Kindly guide me


4 Replies
Did you try the approach listed here? You will need to have a shareable link for the file.
Did this help?
Any update?

Create a scheduled task for this 

# Define the date format for the filename
$dateFormat = "yyyyMMdd"

# Define the folder path to save the downloaded file
$folderPath = "C:\Downloads"

# Define the file name with current date
$fileName = "ExcelFile_$(Get-Date -Format $dateFormat).xlsx"

# Set up Google Drive API credentials
$clientId = "YOUR_CLIENT_ID"
$clientSecret = "YOUR_CLIENT_SECRET"
$refreshToken = "YOUR_REFRESH_TOKEN"

# Authenticate with Google Drive API
$authUrl = ""
$body = @{
    client_id     = $clientId
    client_secret = $clientSecret
    refresh_token = $refreshToken
    grant_type    = "refresh_token"

$response = Invoke-RestMethod -Uri $authUrl -Method POST -Body $body
$accessToken = $response.access_token

# Download the Excel file from Google Drive
$fileId = "YOUR_FILE_ID"
$url = "$fileId/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
$headers = @{
    Authorization = "Bearer $accessToken"

$response = Invoke-WebRequest -Uri $url -Headers $headers -OutFile "$folderPath\$fileName"