Introduction 


Managing files across multiple cloud storage platforms can be a cumbersome and time-consuming task. For many users, manually transferring files between Google Drive and Microsoft OneDrive involves downloading files from one service and uploading them to the other, often re-organizing and converting formats along the way. This repetitive process wastes valuable time and increases the risk of errors or data loss. 


Fortunately, automation can dramatically simplify this workflow. The Google Drive to OneDrive Automation with Google Apps Script leverages Google Apps Script and Microsoft Graph API to automate the entire process of syncing files between your Google Drive and OneDrive accounts. By utilizing secure OAuth2 authorization and a user-friendly sidebar interface, this script ensures a smooth, efficient, and reliable file transfer process. 


This guide will walk you through everything you need to know—from setting up the script, authorizing your Microsoft account, to automatically converting Google-native files to Microsoft Office formats before upload. Whether you are backing up data, collaborating across platforms, or consolidating storage, this solution offers an elegant and automated way to keep your files synchronized with minimal effort. 


Key Features 


This integration script is packed with powerful features to make your file management seamless: 


OAuth2 Secure Authorization: Uses Microsoft Graph API’s OAuth2 protocol for secure and seamless access to your OneDrive account without compromising your credentials. 
 
 

Dynamic Credential Input: Credentials like Client ID, Client Secret, Tenant ID, and Redirect URI are entered through a simple sidebar, eliminating the need for manual code changes. 
 
 

Custom Google Sheets Menu: A custom menu named “OneDrive Integration” appears in your Google Sheet to control authorization, file transfers, and resetting credentials. 
 
 

Automatic File Conversion: Converts Google Docs, Sheets, and Slides to Microsoft Word, Excel, and PowerPoint formats before uploading, ensuring compatibility. 
 
 

Comprehensive Logging: Tracks every file upload's status directly in the spreadsheet, providing clear insight into successful transfers and any errors encountered. 
 
 

Supports Multiple File Types: Uploads regular files like PDFs and images directly, while converting Google-native formats automatically. 
 
 


Step-by-Step Google Drive to OneDrive Automation


Step 1: Open Google Sheets and Create Apps Script Project 


Start by opening a new or existing Google Sheets document where you want to run this automation. Navigate to the menu, click Extensions, then select Apps Script to open the Google Apps Script editor. This editor is where you will paste and manage all the necessary code for the integration. 



Step 2: Add Script Files 


Inside the Apps Script editor, create a new script file named oneDriveUploader.gs and paste the main script code responsible for handling file uploads and conversions. Then, create another script file called OAuth2.gs. This should contain the OAuth2 library code sourced from the official Google Workspace OAuth2 library. Finally, create an HTML file named Sidebar.html that contains the user interface for entering Microsoft app credentials through a sidebar in your spreadsheet. 


Step 3: Enter Microsoft App Credentials 


Return to your Google Sheet. You will see a new custom menu called “OneDrive Integration”. Click Enter Credentials to open the sidebar form. Here, input your Microsoft Azure app credentials — including the Client ID, Client Secret, Tenant ID, and Redirect URI. These credentials allow the script to authenticate and securely interact with your OneDrive account. 


Step 4: Authorize Access to OneDrive 


After entering credentials, click the Authorize button in the sidebar. This will prompt you to log into your Microsoft account and grant permissions for the script to access your OneDrive files. Once authorized, the script stores access and refresh tokens securely, allowing for ongoing communication without repeatedly asking for login. 


Step 5: Start File Transfer 


Once authorization is complete, use the Copy Files option from the OneDrive Integration menu to begin the file transfer process. The script scans your entire Google Drive, converts any Google-native files (Docs, Sheets, Slides) into Microsoft Office-compatible formats (Word, Excel, PowerPoint), and uploads them automatically to the root directory of your OneDrive. 

Step 6: Monitor Upload Status 


Throughout the process, the script logs the status of each file upload directly within your Google Sheet, showing success or detailed error messages if any issues occur. This transparent logging allows you to track progress in real-time and quickly troubleshoot failed transfers or conversion problems. 


How It Works Behind the Scenes


 When you open your Google Sheet, the script injects a custom menu for easy access. When you input your Microsoft app credentials, the script uses OAuth2 to securely obtain access tokens from Microsoft Graph API. These tokens allow the script to communicate with your OneDrive account. 


The script iterates through all your Google Drive files, identifying those needing conversion. Google Docs, Sheets, and Slides are converted into Office formats to ensure they are usable on OneDrive. Other files, like PDFs and images, are uploaded as-is. Using Microsoft Graph API, each file is uploaded into your OneDrive root folder, and the upload status is recorded back in your sheet. 


If you choose to reset credentials, the script clears saved tokens to allow reauthorization with a different account or to fix issues. 


Supported File Types and Conversion 


Supported file types and their conversions include Google Docs, which are converted to Microsoft Word (.docx), Google Sheets to Microsoft Excel (.xlsx), and Google Slides to Microsoft PowerPoint (.pptx), all of which are converted before upload. PDFs, images, and other formats are uploaded as-is without any conversion. Unsupported formats or any errors during conversion are recorded in the status log, enabling you to review and resolve issues as needed. 


Example Status Log in Google Sheet 



Common Issues and Troubleshooting 


Authorization Errors: Ensure your Microsoft Azure app credentials are correct and that you have granted all required permissions during the OAuth2 login. 
 
 

Conversion Failures: Sometimes Google files may fail conversion if they are corrupted or contain unsupported elements. Review logs to identify problematic files. 
 
 

Upload Failures: Network interruptions or API rate limits can cause upload errors. Retry after some time or check your Microsoft Graph API quota. 
 
 

Conclusion 


Automating your file transfers from Google Drive to OneDrive using Google Apps Script saves time, reduces errors, and simplifies cross-platform file management. With secure OAuth2 authorization, seamless file format conversion, and detailed logging, this script empowers you to keep your files synchronized effortlessly. 

Whether you are backing up important documents, migrating data, or working across Google and Microsoft ecosystems, this automation is a powerful tool in your cloud storage arsenal. Setup is straightforward and flexible, and once running, it can be scheduled to execute regularly for hands-free file syncing.