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.
InstallationPowerShell 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:
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
C:\Program Files (x86)\Google\CloudSDK\google-cloud-sdk\platform\GoogleCloudPowerShell\
AuthenticationAs with any other Google Cloud APIs, you need to be authenticated before you can use cmdlets. Here's the gcloud command to do that:
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.
The full list of Cloud Storage cmdlets can be found here.