{"id":17381809,"url":"https://github.com/MVKozlov/GMGoogleDrive","last_synced_at":"2026-08-16T09:30:26.682Z","repository":{"id":20055787,"uuid":"88717616","full_name":"MVKozlov/GMGoogleDrive","owner":"MVKozlov","description":"Google Drive REST Api module for Powershell","archived":false,"fork":false,"pushed_at":"2026-03-06T09:04:56.000Z","size":193,"stargazers_count":50,"open_issues_count":0,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2026-03-06T12:37:43.670Z","etag":null,"topics":["google","google-api","google-drive","googledrive","powershell","powershell-module","rest"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MVKozlov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-04-19T07:59:45.000Z","updated_at":"2026-03-06T08:12:35.000Z","dependencies_parsed_at":"2023-02-17T15:15:45.962Z","dependency_job_id":"7774e60e-bed8-4357-bb76-e9182b75ed6d","html_url":"https://github.com/MVKozlov/GMGoogleDrive","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/MVKozlov/GMGoogleDrive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MVKozlov%2FGMGoogleDrive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MVKozlov%2FGMGoogleDrive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MVKozlov%2FGMGoogleDrive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MVKozlov%2FGMGoogleDrive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MVKozlov","download_url":"https://codeload.github.com/MVKozlov/GMGoogleDrive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MVKozlov%2FGMGoogleDrive/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":36711342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-08-06T04:43:03.162Z","status":"online","status_checked_at":"2026-08-16T02:00:06.462Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google","google-api","google-drive","googledrive","powershell","powershell-module","rest"],"created_at":"2024-10-16T07:01:54.570Z","updated_at":"2026-08-16T09:30:26.676Z","avatar_url":"https://github.com/MVKozlov.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"# GMGoogleDrive Powershell Module\n\n[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/GMGoogleDrive.svg)](https://www.powershellgallery.com/packages/GMGoogleDrive/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nGoogle Drive REST API module for Powershell with Google Sheets API support.\n\n## Table of Contents\n\n- [GMGoogleDrive Powershell Module](#gmgoogledrive-powershell-module)\n  - [Table of Contents](#table-of-contents)\n  - [Google Project Setup](#google-project-setup)\n    - [Project Creation](#project-creation)\n    - [API Setup](#api-setup)\n    - [Credentials Setup](#credentials-setup)\n      - [OAuth 2.0](#oauth-20)\n        - [OAuth 2.0 Consent Screen](#oauth-20-consent-screen)\n        - [OAuth 2.0 Credentials](#oauth-20-credentials)\n      - [Service Account](#service-account)\n  - [Authorization Code and Refresh Token Retrieval](#authorization-code-and-refresh-token-retrieval)\n    - [Using Powershell](#using-powershell)\n      - [Authorization Code](#authorization-code)\n      - [Refresh Token](#refresh-token)\n    - [Manually](#manually)\n  - [Access Token Retrieval](#access-token-retrieval)\n  - [Usage](#usage)\n  - [Error Handling](#error-handling)\n  - [Automation](#automation)\n\n---\n\n## Google Project Setup\n\nGoogle Drive is a free service for file storage files. In order to use this storage you need a Google user which will own the files, and a Google API client.\n\n### Project Creation\n\nYou need to create a Google project and enable the Google Drive API and Google Sheets API for it to use this module.\n\n1. Navigate to the [Google Cloud Console](https://console.cloud.google.com/projectcreate), create a new project and  give it a name of your choosing.\n   - You should be redirected to the [Project Dashboard](https://console.cloud.google.com/home/dashboard) for your new project.\n\n### API Setup\n\n1. Go to [APIs \u0026 Services](https://console.cloud.google.com/apis/dashboard)\n   - Click on **Enable APIs and Services**.\n   - Search for `Google Drive API`, click on it and then click **Enable**.\n   - Search for `Google Sheets API`, click on it and then click **Enable**.\n\n### Credentials Setup\n\n#### OAuth 2.0\n\n##### OAuth 2.0 Consent Screen\n\nBefore setting up OAuth 2.0 credentials, you need to set up the OAuth consent screen. This is a one-time setup for your project. The consent screen is what users will see when they are asked to authorize your application to access their Google Drive files.\n\n1. Navigate to [APIs \u0026 Services](https://console.cloud.google.com/apis/dashboard)\n1. Navigate to [OAuth consent screen](https://console.cloud.google.com/auth/overview)\n   - Click on `Get Started`\n   - Under `App Information` fill in the following fields:\n      - `App name` - be aware of the [naming restrictions](https://support.google.com/cloud/answer/15549049#zippy=%2Capp-name)\n      - `User support email` - normally your email address\n   - Under `Audience`:\n      - Select `Internal` if you are using a Google Workspace account\n      - Select `External` if you are using a personal account\n   - Under `Contact Information` fill in the following fields:\n      - `Email address` - same as `User support email`\n1. Click on [Audience](https://console.cloud.google.com/auth/audience) and under `Test Users` add the email addresses of the users who will be testing/using your application.\n\n\u003e [!NOTE]\n\u003e Be aware of the limitations of an `External` application that is under **`Testing`** mode. The refresh token will expire after 7 days. If you want to have a non-expiring refresh token, you need to publish your application or use an `Internal` application.\n\n##### OAuth 2.0 Credentials\n\n1. Navigate to [APIs \u0026 Services](https://console.cloud.google.com/apis/dashboard)\n1. Navigate to [Credentials](https://console.cloud.google.com/apis/credentials)\n   - Click on `Create Credentials` and select `OAuth client ID`\n   - Under `Application type` select `Web application`\n   - Under `Authorized redirect URIs` add the following URI `https://developers.google.com/oauthplayground`\n   - Click on `Create`\n   - Click on `Download JSON` to download the credentials file. This file contains your `Client ID` and `Client Secret`.\n\n\u003e [!WARNING]\n\u003e\n\u003e Make sure that the redirect URI does not have a trailing `/` at the end.\n\nHere's how you can reference the credentials in your code:\n\n```powershell\n$oAuthJson = Get-Content -Path 'C:\\path\\to\\your\\credentials.json' |\n    ConvertFrom-Json\n```\n\n#### Service Account\n\nUsing a service account allows you to upload data to folders that are shared with the service account.\n\nIn Google Workspace enterprise environments, it is also possible to grant impersonation rights to the service account. With these rights, the service account can act as a user (without OAuth consent screen).\n\nPlease check the Google documentation:\n\n- [Create a service account](https://developers.google.com/workspace/guides/create-credentials#create_a_service_account)\n- [Assign impersonation rights (domain-wide delegation)](https://developers.google.com/workspace/guides/create-credentials#optional_set_up_domain-wide_delegation_for_a_service_account)\n\nGoogle offers two types of service user files `.json` and `.p12`. Both types are implemented in this module.\n\n```powershell\nGet-GDriveAccessToken -Path D:\\service_account.json `\n-JsonServiceAccount -ImpersonationUser \"user@domain.com\"\n```\n\n```powershell\n$keyData = Get-Content -AsByteStream -Path D:\\service_account.p12\n\nGet-GDriveAccessToken -KeyData $KeyData `\n    -KeyId 'd41d8cd98f0b24e980998ecf8427e' `\n    -ServiceAccountMail test-account@980998ecf8427e.iam.gserviceaccount.com `\n    -ImpersonationUser \"user@domain.com\"\n```\n\n## Authorization Code and Refresh Token Retrieval\n\n### Using Powershell\n\n#### Authorization Code\n\n```powershell\n$authorizationCode = Request-GDriveAuthorizationCode -ClientID $oAuthJson.web.client_id `\n-ClientSecret $oAuthJson.web.client_secret\n```\n\n#### Refresh Token\n\n``` powershell\n$refreshToken = Request-GDriveRefreshToken -ClientID $oAuthJson.web.client_id `\n-ClientSecret $oAuthJson.web.client_secret `\n-AuthorizationCode $authorizationCode\n```\n\n### Manually\n\n1. Browse to [OAuth 2.0 Playground](https://developers.google.com/oauthplayground)\n1. Click the gear in the right-hand corner and place a checkmark next to \"Use your own OAuth credentials\"\n   - Fill in the `OAuth Client ID` and `OAuth Client Secret` fields with the values from your credentials file.\n1. Under `Select \u0026 authorize APIs` search and select the following scopes:\n    1.Under `Drive API v3` select the following scopes:\n      - `https://www.googleapis.com/auth/drive`\n      - `https://www.googleapis.com/auth/drive.file`\n1. Under `Google Sheets API v4` select the following scopes:\n      - `https://www.googleapis.com/auth/spreadsheets`\n1. Click on `Authorize APIs` and follow the prompts to authorize the application.\n1. Click on `Exchange authorization code for tokens` to get the your `Refresh token`.\n\n\u003e [!CAUTION]\n\u003e The `Refresh token` can only be retrieved once. If you lose it, you will need to repeat the authorization process to get a new one.\n\n## Access Token Retrieval\n\n\u003e [!TIP]\n\u003e The `Access Token` is a mandatory parameter for almost every `GDrive` cmdlet. It is valid for 1 hour and needs to be refreshed every hour.\n\n```powershell\n$accessToken = Get-GDriveAccessToken -ClientID $oAuthJson.web.client_id `\n    -ClientSecret $oAuthJson.web.client_secret `\n    -RefreshToken $refreshToken.refresh_token\n```\n\n## Usage\n\n``` powershell\n# Upload new file\nAdd-GDriveItem -AccessToken $access.access_token -InFile D:\\SomeDocument.doc -Name SomeDocument.doc\n\n# Search existing file\nFind-GDriveItem -AccessToken $access.access_token -Query 'name=\"test.txt\"'\n\n# Update existing file contents\nSet-GDriveItemContent -AccessToken $access.access_token -ID $file.id -StringContent 'test file'\n\n# Get ParentFolderID and Modified Time for file\nGet-GDriveItemProperty -AccessToken $access.access_token -ID $file.id -Property parents, modifiedTime\n\n# and so on :)\n```\n\n## Error Handling\n\nCmdlets will exit at the first error. However, for instance if \"Metadata Upload\" succeeded but content upload failed, `UploadID` is returned as `ResumeID` to resume operations later.\n\nYou can further leverage `Get-GDriveError` to get more information about the error by catching it in a try/catch block.\n\n``` powershell\n# Catch error\ntry {\n    Get-GDriveItemProperty -AccessToken 'error token' -id 'error id'\n    }\n    catch {\n        $err = $_\n    }\n\n# Decode error message\n Get-GDriveError $err\n```\n\n## Automation\n\nIn order to automate operations, you can use the `Get-GDriveAccessToken` cmdlet to retrieve an access token and then use that token.\n\nThe functions below are meant to be used as an example only. It is outside of the scope of this module to provide a secure way to store your credentials. You can use the `Protect-String` and `Unprotect-String` functions to convert a string to a secure string and back.\n\n\u003e [!IMPORTANT]\n\u003e `ConvertTo-SecureString` and `ConvertFrom-SecureString` use the Windows Data Protection API (DPAPI) to encrypt and decrypt the string.\n\u003e This means that the encrypted string can only be decrypted on the **same machine** that it was encrypted on and by the **user account** that it was encrypted by.\n\n``` powershell\nfunction Protect-String {\n    \u003c#\n        .SYNOPSIS\n            Convert String to textual form of SecureString\n        .PARAMETER String\n            String to convert\n        .OUTPUTS\n            String\n        .NOTES\n            Author: MVKozlov\n    #\u003e\n    param(\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\n        [string]\n        $String\n    )\n\n    PROCESS {\n        $String | ConvertTo-SecureString -AsPlainText -Force |\n            ConvertFrom-SecureString\n    }\n}\n\nfunction Unprotect-String {\n    \u003c#\n        .SYNOPSIS\n            Convert SecureString to string\n        .PARAMETER String\n            String to convert (textual form of SecureString)\n        .PARAMETER SecureString\n            SecureString to convert\n        .OUTPUTS\n            String\n        .NOTES\n            Author: MVKozlov\n    #\u003e\n    [CmdletBinding(DefaultParameterSetName = 'String')]\n    param(\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0, ParameterSetName = 'String')]\n        [string]\n        $String,\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0, ParameterSetName = 'SecureString')]\n        [securestring]\n        $SecureString\n    )\n\n    PROCESS {\n        if ($String) {\n            $SecureString = $String | ConvertTo-SecureString\n        }\n\n        if ($SecureString) {\n        (New-Object System.Net.NetworkCredential '', ($SecureString)).Password\n        }\n    }\n}\n```\n\n1. Open Powershell on the machine that will run the script using the specified user account.\n\n    ```powershell\n    # Method 1: Using runas command\n    runas /user:DOMAIN\\username powershell.exe\n\n    # Method 2: Using the `-Credential` parameter of Start-Process\n    Start-Process powershell.exe -Credential (Get-Credential)\n    ```\n\n1. Use the `Protect-String` function to convert your credentials to a secure string and save it to a file.\n\n    ```powershell\n    $credentials = [PSCustomObject]@{\n        ClientID = 'clientid'\n        ClientSecret = 'clientsecret'\n        RefreshToken = 'refreshtoken'\n    } | ConvertTo-Json | Protect-String |\n        Set-Content -Path C:\\Path\\somefile -Value $credentials\n    ```\n\n1. In your automated script, use the `Unprotect-String` function to retrieve the credentials and use them to get the access token.\n\n    ```powershell\n    $credentials = Get-Content -Path C:\\path\\somefile |\n        Unprotect-String | ConvertFrom-Json\n\n    try {\n        Write-Host \"Getting access token...\"\n\n        $token = Get-GDriveAccessToken -ClientID $credentials.ClientID `\n            -ClientSecret $credentials.ClientSecret `\n            -RefreshToken $credentials.RefreshToken\n\n        Write-Host \"Token expires $((Get-Date).AddSeconds($token.expires_in))\"\n    }\n    catch {\n        Write-Warning \"Error retrieving access token $_\"\n        Get-GDriveError $_\n    }\n\n    if ($token) {\n        $Summary = Get-GDriveSummary -AccessToken $token.access_token `\n        -ErrorAction Stop\n        # [rest of your code here]\n    }\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMVKozlov%2FGMGoogleDrive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMVKozlov%2FGMGoogleDrive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMVKozlov%2FGMGoogleDrive/lists"}