Ready to get started?

Learn more about the CData ADO.NET Provider for Google Drive or download a free trial:

Download Now

Automate Google Drive Integration Tasks from PowerShell

Are you looking for a quick and easy way to access Google Drive data from PowerShell? We show how to use the Cmdlets for Google Drive and the CData ADO.NET Provider for Google Drive to connect to Google Drive data and synchronize, automate, download, and more.

The CData Cmdlets for Google Drive are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Google Drive.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Google Drive API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Google Drive data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Google Drive. To access Google Drive data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Google Drive.

After obtaining the needed connection properties, accessing Google Drive data in PowerShell consists of three basic steps.

You can connect to Google APIs on behalf of individual users or on behalf of a domain. Google uses the OAuth authentication standard. See the "Getting Started" section of the help documentation for a guide.

PowerShell

  1. Install the module:

    Install-Module GoogleDriveCmdlets
  2. Connect:

    $googledrive = Connect-GoogleDrive
  3. Search for and retrieve data:

    $starred = "true" $files = Select-GoogleDrive -Connection $googledrive -Table "Files" -Where "Starred = `'$Starred`'" $files

    You can also use the Invoke-GoogleDrive cmdlet to execute SQL commands:

    $files = Invoke-GoogleDrive -Connection $googledrive -Query 'SELECT * FROM Files WHERE Starred = @Starred' -Params @{'@Starred'='true'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Google Drive\lib\System.Data.CData.GoogleDrive.dll")
  2. Connect to Google Drive:

    $conn= New-Object System.Data.CData.GoogleDrive.GoogleDriveConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the GoogleDriveDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Name, Size from Files" $da= New-Object System.Data.CData.GoogleDrive.GoogleDriveDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.size }

Update Google Drive Data

PowerShell

Update-GoogleDrive -Connection $GoogleDrive -Columns @('Name','Size') -Values @('MyName', 'MySize') -Table Files -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleDrive.GoogleDriveCommand("UPDATE Files SET Starred='true' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleDrive.GoogleDriveParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Google Drive Data

PowerShell

Add-GoogleDrive -Connection $GoogleDrive -Table Files -Columns @("Name", "Size") -Values @("MyName", "MySize")

ADO.NET

$cmd = New-Object System.Data.CData.GoogleDrive.GoogleDriveCommand("INSERT INTO Files (Starred) VALUES (@myStarred)", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleDrive.GoogleDriveParameter("@myStarred","true")) $cmd.ExecuteNonQuery()

Delete Google Drive Data

PowerShell

Remove-GoogleDrive -Connection $GoogleDrive -Table "Files" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleDrive.GoogleDriveCommand("DELETE FROM Files WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleDrive.GoogleDriveParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()