Last month, Google released a Systems Developer Kit called Cloud Tools for PowerShell that allows PowerShell to connect with and manage Google Cloud Platform Services. In this article, we talk about PowerShell and then demonstrate how to install the gcloud PowerShell SDK, connect to the Google Cloud Platform, and run a few commands against an existing GCP SQL instance.
Avatar

This release falls in line with recent PowerShell developments, such as running bash commands in PowerShell. Last month, PowerShell celebrated its 10-year anniversary; if you missed it, take a look at the PowerShell “Then and Now” keynote address here with J. Snover, K. Hansen, and K. Banston. The video expresses PowerShell’s goals from the beginning of its implementation, utilizing and building upon the best UNIX ideas, such as wildcards, modules, -confirm, and output. I believe this poignant quote captures the essence of PowerShell’s abilities is:

… What PowerShell does so wonderfully is glues together this completely messy disjointed world and tries to bring it to this object-oriented-appearing approach.

I believe that bringing together different technologies in PowerShell is a worthwhile ambition and commend the investment Microsoft continues to place in PowerShell. It’s nice to see a technology that puts users and admins first, making our job more fun and allowing us to get the job done and go home.

Google Cloud SDK Setup

The Google Cloud SDK has no prerequisites other than Windows 7 SP1 or Windows 10 with PowerShell v5 installed. You will want to have an existing Google Cloud Platform account and have a running instance so you can establish a connection to the GCP. In this setup guide, we’ll use an existing SQL instance for testing, which we set up and demonstrated in our two previous GCP articles here.

To get the SDK setup started, first visit Cloud Tools for PowerShell and click on the button labeled “Get Cloud SDK for Windows.” On the following page, click on the Windows Cloud SDK installer. After the download completes, you’ll have a file named GoogleCloudSDKInstaller.exe. Double-click on the file and the installation wizard will start:

Google cloud SDK setu

Google cloud SDK setu

Click Next > I Agree to the terms of use and then choose the install type: Single User or All users. Then set the default Destination Folder and click Next. Select the components you want to install and click the Install button.

Cloud tools setup add beta commands

Cloud tools setup add beta commands

The space required will be about 90MB. Click on the Show details button during the installation to get an idea of the commands that will be available:

Google cloud SDK setup details

Google cloud SDK setup details

Click Next to finish the installation and make sure to check the box labeled “Run ‘gcloud init’ to configure the Cloud SDK,” and then click Finish.

Immediately a command prompt will open and run a script that welcomes you, does a network connection test, and asks to log in (Y/n)?

Gcloud init login

Gcloud init login

Hit Y and then Enter. Immediately your default web browser will launch and ask you to choose a Google account to log into; the command prompt will also display the URL, which you can copy if necessary, that launches:

SDK setup Google account sign in

SDK setup Google account sign in

After logging into your Google Cloud Platform account, accept the following permissions by clicking the Allow button:

SDK request for permissions

SDK request for permissions

The website and our command prompt will confirm we’ve authenticated. In the command prompt dialog, we select the project we want to use [2], which is the SQL Instance that we set up in our previous Google SQL Instance articles.

Google Cloud SDK authenticated

Google Cloud SDK authenticated

Next is displayed some setup, version, and command information, and we arrive at the command prompt C:\Program Files (x86)\Google\Cloud SDK>. However, we want to switch gears, leave open the original command prompt, and open our new Cloud Tools for PowerShell executable that we can find in the Windows Start Menu application search box; when we search for “PowerShell.”

PowerShell Cloud Tools executable

PowerShell Cloud Tools executable

Issuing commands with Cloud Tools for PowerShell

To see the account we’re using and the project we’re in, run the command:

gcloud config list
Gcloud config list

Gcloud config list

To see the properties of the SDK as well as version numbers and system paths, run the command:

gcloud info
Powershell gcloud auth and info

Powershell gcloud auth and info

To confirm we have new cmdlets in PowerShell, we can run the command:

Get-Command gcloud
PowerShell Get Command gcloud

PowerShell Get Command gcloud

Because we have an SQL Instance already running, we want to see the commands available to us to manage our Google Cloud Platform SQL Instance.

To see a list of our groups and commands, issue the command:

gcloud –help

One command group we find is ‘sql’, so to view commands available to use inside that group, we issue the command:

gcloud sql –help

Building upon our results, we issue the command:

gcloud sql instances –help 
Gcloud SQL Instances help

We now have the ability to use PowerShell to perform or script any number of actions including create, restart, backup, import, and export data, as well as instances within the Google Cloud Platform—pretty cool!

Subscribe to 4sysops newsletter!

Conclusion

As you can see, the setup of the Google Cloud Tools SDK is actually pretty simple, and that the new cmdlet provides us a very powerful interface into the Google Cloud Platform. With the GCP now just another cmdlet in PowerShell, another messy, disjointed cloud technology has been pulled into a coherent, connected, single interface.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account