Download file from Gdrive

Copper Contributor

Dears,
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

Regards,

4 Replies
Did you try the approach listed here? https://www.reddit.com/r/PowerShell/comments/phkr76/trying_to_download_google_drive_file_in/ 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 = "https://accounts.google.com/o/oauth2/token"
$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 = "https://www.googleapis.com/drive/v3/files/$fileId/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
$headers = @{
    Authorization = "Bearer $accessToken"
}

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

@faisalce