![]() |
VOOZH | about |
The CData Cmdlets for Google Cloud Storage are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Google Cloud Storage.
The Cmdlets are not only a PowerShell interface to Google Cloud Storage, but also an SQL interface; this tutorial shows how to use both to retrieve Google Cloud Storage data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Google Cloud Storage. To access Google Cloud Storage data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Google Cloud Storage.
Once you have acquired the necessary connection properties, accessing Google Cloud Storage data in PowerShell can be enabled in three steps.
You can connect without setting any connection properties for your user credentials. After setting InitiateOAuth to GETANDREFRESH, you are ready to connect.
When you connect, the Google Cloud Storage OAuth endpoint opens in your default browser. Log in and grant permissions, then the OAuth process completes
Service accounts have silent authentication, without user authentication in the browser. You can also use a service account to delegate enterprise-wide access scopes.
You need to create an OAuth application in this flow. See the Help documentation for more information. After setting the following connection properties, you are ready to connect:
The OAuth flow for a service account then completes.
Install the module:
Install-Module GoogleCloudStorageCmdlets
Connect:
$googlecloudstorage = Connect-GoogleCloudStorage -ProjectId "$ProjectId" -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$name = "TestBucket" $buckets = Select-GoogleCloudStorage -Connection $googlecloudstorage -Table "Buckets" -Where "Name = `'$Name`'" $buckets
You can also use the Invoke-GoogleCloudStorage cmdlet to execute SQL commands:
$buckets = Invoke-GoogleCloudStorage -Connection $googlecloudstorage -Query 'SELECT * FROM Buckets WHERE Name = @Name' -Params @{'@Name'='TestBucket'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Google Cloud Storage\lib\System.Data.CData.GoogleCloudStorage.dll")
Connect to Google Cloud Storage:
$conn= New-Object System.Data.CData.GoogleCloudStorage.GoogleCloudStorageConnection("ProjectId='project1';InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the GoogleCloudStorageDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, OwnerId from Buckets"
$da= New-Object System.Data.CData.GoogleCloudStorage.GoogleCloudStorageDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.name $_.ownerid
}
Download a free trial of the Google Cloud Storage Data Provider to get started:
Download NowLearn more:
👁 Google Cloud Storage IconRapidly create and deploy powerful .NET applications that integrate with Google Cloud Storage.