Automate Google Cloud Storage Integration Tasks from PowerShell
The CData ADO.NET Provider for Google Cloud Storage is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Google Cloud Storage.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Google Cloud Storage; this tutorial shows how to use the Provider to retrieve Google Cloud Storage data.
Once you have acquired the necessary connection properties, accessing Google Cloud Storage data in PowerShell can be enabled in three steps.
Authenticate with a User Account
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
Authenticate with a Service Account
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:
- InitiateOAuth: Set this to GETANDREFRESH.
- OAuthJWTCertType: Set this to "PFXFILE".
- OAuthJWTCert: Set this to the path to the .p12 file you generated.
- OAuthJWTCertPassword: Set this to the password of the .p12 file.
- OAuthJWTCertSubject: Set this to "*" to pick the first certificate in the certificate store.
- OAuthJWTIssuer: In the service accounts section, click Manage Service Accounts and set this field to the email address displayed in the service account Id field.
- OAuthJWTSubject: Set this to your enterprise Id if your subject type is set to "enterprise" or your app user Id if your subject type is set to "user".
- ProjectId: Set this to the Id of the project you want to connect to.
The OAuth flow for a service account then completes.
-
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 }