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.
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
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:
$ gcloud auth login
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:
- 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.