Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / PowerShell

Use PowerShell to List Google Docs

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
18 Apr 2012CPOL 13.1K   4  
The Google Data Provider provides an easy-to-use ADO.NET interface that you can take advantage of with your PowerShell Scripts.

Are you looking for a quick and easy way to access your Google Docs from PowerShell? The Google Data Provider provides an easy-to-use ADO.NET interface that you can take advantage of with your PowerShell Scripts. Simply use the included SQL like .NET objects (GoogleConnection, GoogleCommand, GoogleDataAdapter, etc.) in your PowerShell scripts to connect to your Google Apps accounts and synchronize, automate, download, and more!

Using the Google Data Provider in PowerShell to List Google Docs

PowerShell
# Load the Google Data Provider assembly 
[Reflection.Assembly]::LoadFile("C:\Program Files\RSSBus\RSSBus 
        Google Data Provider\lib\System.Data.RSSBus.Google.dll")

# Connect to Google 
$constr = "User=[username];Password=[password]"
$conn= New-Object System.Data.RSSBus.Google.GoogleConnection($constr)
$conn.Open()

$sql="SELECT Name, AuthorName, Type, Updated, Weblink from Documents"

$da= New-Object System.Data.RSSBus.Google.GoogleDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)

$dt.Rows | foreach {
	Write-Host $_.updated $_.name
}

Listing is only the first step. With full CRUD support, you can use the Google Data Provider to easily upload and download documents as well. The following bit of PowerShell code downloads one of the documents listed above.

Download a File from Google Docs

PowerShell
$cmd= New-Object System.Data.RSSBus.Google.GoogleCommand("DownloadDocument", $conn)
$cmd.CommandType= [System.Data.CommandType]'StoredProcedure'
$cmd.Parameters.Add( (New-Object System.Data.RSSBus.Google.GoogleParameter("@Type", "TXT")) ) 
$cmd.Parameters.Add( (New-Object System.Data.RSSBus.Google.GoogleParameter("@Name", "myfile")) ) 
$cmd.Parameters.Add
( (New-Object System.Data.RSSBus.Google.GoogleParameter("@LocalFile", "d:\myfile.txt")) ) 
$reader = $cmd.ExecuteReader()

Likewise, calling the UploadDocument Stored Procedure allows your scripts to upload documents directly to Google Docs.

As you can see, the Google Data Provider provides a hassle-free way to access the features of Google Apps directly from PowerShell script, and eliminates the headache involved with authentication, security, etc. Happy scripting!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
RSSBus (www.rssbus.com) provides high-performance, reliable, and fully-extensible products that simplify the process of producing, consuming, and integrating data. The RSSBus products enable a simple yet effective layer of middleware that helps users drive information flow without the added complexity that is common across other integration solutions.

Comments and Discussions

 
-- There are no messages in this forum --