Running Powershell on Google Cloud SDK



It’s exciting to see so many options for .NET developers to manage their cloud resources on Google Cloud Platform. Apart from the usual Google Cloud Console, there's Cloud Tools for Visual Studio, and the subject of this post: Cloud Tools for PowerShell.

PowerShell is a command-line shell and associated scripting language built on the .NET Framework. It's the default task automation and configuration management tool used in the Windows world. A PowerShell cmdlet is a lightweight command invoked within PowerShell.

Cloud Tools for PowerShell is a collection of cmdlets for accessing and manipulating GCP resources. It's currently in beta and allows access to Google Compute Engine, Google Cloud Storage, Google Cloud SQL and Google Cloud DNS —with more to come! For other services, you can still use the gcloud command line tool inside Google Cloud SDK Shell.

Installation


PowerShell cmdlets come as part of the Cloud SDK for Windows installation, so make sure that you’ve checked the PowerShell option when installing Cloud SDK.

If you want to add PowerShell cmdlets into an existing Cloud SDK installation, you’ll need to do a little more work.

First, you need to install cmdlets using gcloud:

$ gcloud components install powershell

Second, you need to register cmdlets with your PowerShell environment. This is done by running a script named AppendPsModulePath.ps1 (provided by Cloud SDK) in PowerShell. Depending on whether Cloud SDK was installed per user or for all users, you can find this script either in

%AppData%\..\Local\Google\CloudSDK\google-cloud-sdk\platform\GoogleCloudPowerShell\

or

C:\Program Files (x86)\Google\CloudSDK\google-cloud-sdk\platform\GoogleCloudPowerShell\

Authentication

As with any other Google Cloud APIs, you need to be authenticated before you can use cmdlets. Here's the gcloud command to do that:

$ gcloud auth login


PowerShell cmdlets


Once authenticated, you're ready to use GCP cmdlets within PowerShell. Here’s an example of using Get-GceInstance cmdlet to list properties of a Compute Engine instance:


Here’s another example of creating a Google Cloud Storage bucket using New-GcsBucket cmdlet:

Here are some of the tasks you can perform with PowerShell cmdlets against a Google Compute Engine instance:

  • Create a Compute Engine VM instance.
  • Start, stop and restart an instance.
  • Add or remove a firewall rule.
  • Create a disk snapshot.

Some of the tasks you can perform against Google Cloud Storage are:

  • Create a storage bucket.
  • List all the buckets in the project.
  • List the contents of a bucket.
  • Get, or delete an item in a bucket.


We also have guides on how to administer Google Cloud SQL instances and how to configure the DNS settings for a domain using Cloud DNS.

The full list of Cloud Storage cmdlets can be found here.


Summary

With Cloud Tools for PowerShell, .NET developers can now script and automate their Compute Engine, Cloud Storage, Cloud SQL and Cloud DNS resources using PowerShell. Got questions? Let us know. Bugs? Report them here. Want to contribute? Great! Care to be part of a UX study? Click here! We’re ramping up our efforts for Windows developers, and would love to hear from you about the direction you want us to take.