Install and Use Cloud Tools for PowerShell

Join Sign in

Install and Use Cloud Tools for PowerShell

1 hour 10 minutes 5 Credits


Google Cloud self-paced labs logo


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 Google Cloud resources such as Compute Engine, Cloud Storage, Google Cloud SQL and Google Cloud DNS.

What you'll learn

In this lab you will learn how to interact with Google Cloud resources from PowerShell, including how to:

  • Install Cloud Tools for PowerShell.

  • Authenticate with the Cloud SDK.

  • Create and manage Compute Engine from PowerShell.

  • Backup data to Cloud Storage from PowerShell.


You should be comfortable with at least the basics of shell programming and virtual machines. If you're not quite ready for an Intermediate level lab, try these labs to get you up to speed:

Setup and Requirements

Do not use the Incognito (Chrome) window.
  • Time. Note the lab’s Completion time, which is an estimate of the time it should take to complete all steps. Plan your schedule so you have time to complete the lab. Once you start the lab, you will not be able to pause and return later (you begin at step 1 every time you start a lab).
  • You do NOT need a Google Cloud account or project. An account, project and associated resources are provided to you as part of this lab.
  • If you already have your own Google Cloud account, make sure you do not use it for this lab.
  • If your lab prompts you to log into the console, use only the student account provided to you by the lab. This prevents you from incurring charges for lab activities in your personal Google Cloud account.
If you have other Google / Gmail accounts, when you log into the student account you may be logged out of those accounts. Alternatively, do not use your Google / Gmail accounts for the lab session, to avoid being logged out of your student account.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.

    Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  5. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

Create a Windows VM with Visual Studio Community Edition Pre-Installed

Open the menu in the upper left corner of the screen:


And click on the Compute Engine > VM instances:


Next, click the Create instance button to create a new virtual machine:


Scroll to the Zone and select zone us-central1-a.


Now scroll down to the Boot Disk section and click the Change button:


On the ensuing “Boot Disk” dialog, select the Custom Images tab. Then, in the Source project for images click Change, then click All tab and select Qwiklabs Resources:


Next, select the image named windows-server-2016-vscommunity-v1 and click the Select button.


Now scroll to the bottom of the Create Instance dialog and click the Create button. After a few minutes, your new instance should look something like this:


Click Check my progress to verify the objective. Create the instance

Connect to your Instance

Now that we have set up our virtual machine (which should look similar to the screenshot below), click the dropdown menu next to RDP.


Click the Set Windows Password button:


A username will be generated.

Click Set to generate a password for this Windows instance. This may take several minutes to complete.

Copy the username and password and save it so you can log into the instance.


Remote desktop (RDP) into the Windows Server

It's time to RDP into the Windows Server. You can RDP directly from the browser using the Spark View extension. Click on Add to Chrome. Then, click Launch app button.

Launch the app

Once launch, a window opens up where you use your Windows username and password (that you saved previously) to connect:

spark-view RDP

Add your VM instance's External IP as your Domain. Click Connect to confirm you want to connect.

Connect to the RDP

When Server Manager opens you are connected to instance-1, the VM instance on the Windows Server.

Copy and paste with the RDP client

Once you are securely logged in to your instance, you may find yourself copying and pasting commands from the lab manual.

  • To paste, hold the CTRL-V keys (if you are a Mac user, using CMND-V will not work.)
  • If you are in a Powershell window, be sure that you have clicked in to the window or else the paste shortcut won't work.
  • If you are pasting into putty, right click.

PowerShell cmdlets come as part of the Cloud SDK for Windows, which is already installed on the Windows VM you provisioned.


Cloud Tools for PowerShell uses the credentials and settings stored in the Cloud SDK. To start using the cmdlets, login using the Cloud SDK.

In your remote session, open the command prompt. Run the following command to start Cloud SDK Shell.

gcloud init

You will be asked to choose the account you would like to use. Enter 2 (Log in with a new account).

Choose the account you would like use to perform operations for this configuration: [1] [2] Log in with a new account Please enter your numeric choice: 2

Enter Y when asked to authenticate with your personal account, which will be the credentials for this session.

It will then prompt you to open a link in your browser to get a verification code. Open the link in your browser (on your local machine). You will be prompted to log in to view the code. Make sure you use the student credentials provided to you by the lab (you can find these under Connection Details page).

Go to the following link in your browser:

Get the verification code from the browser and enter in the Cloud Shell prompt.

You will then be prompted to choose the project. Your cloud project is the Project ID found in the CONNECTION DETAILS section of your lab. Choose the project with your Project ID.

Your current project is now set to [Project ID].

Create and Manage Compute Engine instances

In this section, you create and manage Compute Engine from within Google Cloud Tools for PowerShell.

Launch Powershell

You can find and launch Powershell by either: On the Server Manager menu bar, choose Tools > Windows Powershell.



Click the VM Search Windows icon and type "powershell". Click on Windows Powershell.


From Powershell, make sure Google Cloud cmdlets are installed correctly, by running the Get-GceInstance cmdlet.


This lists the Compute Engine instances you have in your project.


Create an instance configuration

Before creating an instance, you must first create an instance configuration. At minimum this requires a name, a machine type, and a boot disk image or pre-existing boot disk. Use Get-GceImage to create a disk image and New-GceInstanceConfig to create a configuration.

$disk = Get-GceImage "windows-cloud" -Family "windows-2012-r2" $config = New-GceInstanceConfig "my-vm-1" ` -MachineType "n1-standard-4" ` -DiskImage $disk

At this point, you have a configuration that you can use to create an instance.

Create an instance

Use the Add-GceInstance cmdlet to create a new Compute Engine instance. You can specify a project and zone, but if omitted, the parameter values default to those in your current active Cloud SDK configuration. If you specify project, make sure to replace [PROJECT_ID] with your own project id.

$config | Add-GceInstance -Project [PROJECT_ID] -Zone us-central1-a

Click Check my progress to verify the objective. Create the instance using Powershell

Manage an instance

You can use the Get-GceInstance cmdlet to retrieve a project's virtual machine instances. Since the instance name may not be unique across projects or zones, you can specify a Project or Zone parameter to narrow the search. By default the cmdlet uses whatever values are in the active Cloud SDK configuration.

$instance = Get-GceInstance "my-vm-1"

You can set instance tags, disks, access configs, and other metadata after creating your instance with the Set-GceInstance cmdlet. Add some metadata and then remove as follows.

Set-GceInstance $instance -AddMetadata @{"newKey" = "newValue"} Set-GceInstance $instance -RemoveMetadata "newKey" Set-GceInstance $instance -RemoveTag "beta" -AddTag "alpha"

Now, add a tag that you will use later to remove the instance.

Set-GceInstance $instance -AddTag "to-be-removed"

Click Check my progress to verify the objective. Add tags to the instance You can start, stop, or restart an instance using various cmdlets. You can refer to an instance by using the name or the strongly-typed object returned from the Get-GceInstance cmdlet. Play with some of these commands.

Stop-GceInstance $instance Start-GceInstance $instance Restart-GceInstance "my-vm-1"

Finally, when you are finished with the instance, remove it from Compute Engine by using the Remove-GceInstance cmdlet and supplying the tag you specified earlier. Make sure to replace [PROJECT_ID] with your own project id.

Get-GceInstance -Project [PROJECT_ID] | Where { $_.Tags.Items -contains "to-be-removed" } | Remove-GceInstance -WhatIf Read the Cloud Tools for PowerShell cmdlet reference to learn more about Compute Engine cmdlets.

Backup data to Cloud Storage

In this part of the lab, you learn how to back up data from your local machine to Cloud Storage using Cloud Tools for PowerShell.

Create a bucket

Before uploading files to Cloud Storage, you need to create a bucket. Use the New-GcsBucket cmdlet to create a new bucket.

$bucket = "my-gcs-bucket"

Note: After executing the below command, if you receive the message like "Sorry that name is not available", try with any other unique bucket name of your choice.

New-GcsBucket $bucket

Upload files to the bucket

You can use New-GcsObject to upload a file or entire folders to the bucket.

You can upload the contents of a local file to Cloud Storage by using the -File parameter and specifying a file path. Alternatively, you can pass the object's contents as a string via the PowerShell pipeline, or you can use the -Value parameter.

Pick a local file on your machine and upload to your bucket as follows. Make sure to replace the path to your file.

New-GcsObject -Bucket $bucket -File "C:\path\to\some\file\hello.txt"

You can upload an entire directory from the local disk to Cloud Storage by using the -UploadFolder parameter and specifying the folder path. If you do not want the folder to be uploaded directly to the root of the Cloud Storage bucket, use -ObjectNamePrefix to specify a prefix that will be applied to every object uploaded.

Pick a local folder on your machine and upload to your bucket as follows. Make sure to replace the path to your folder.

New-GcsObject -Bucket $bucket -Folder "C:\path\to\some\folder"

Click Check my progress to verify the objective. Create the bucket and upload a file

Search data

You can search data with cmdlets, or with the provider through the common file search cmdlets. Try the following command with your bucket.

Get-GcsObject $bucket | Select Name, Size | Out-GridView

You should see a grid pop-up with name and size.


Read data

You can use the Read-GcsObject cmdlet to read data. As an example, you can use the following command to read a file named hello.txt to your desktop.

Read-GcsObject $bucket "hello.txt" ` -OutFile "$Env:UserProfile\Desktop\hello.txt"

Delete data

Last but not least, you can delete data using the Remove-GcsObject cmdlet. Use the following command to delete all contents of the bucket.

Get-GcsObject $bucket | Remove-GcsObject Read the Cloud Tools for PowerShell cmdlet reference to learn more about Cloud Storage cmdlets.


In this lab, you learned how to manage Compute Engine instances and Cloud Storage buckets from PowerShell but there's more! You can also manage Cloud SQL and Cloud CDN resources using PowerShell. See some suggestions in the "Next Steps" section below to learn more.

Finish Your Quest

This self-paced lab is part of the Windows on Google Cloud quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in this quest and get immediate completion credit if you've taken this lab. See other available quests.

Take Your Next Lab

Continue your quest with Configuring and Deploying Windows SQL Server on Google Cloud, or check out these suggestions:

Next Steps

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated June 2, 2022 Lab Last Tested June 2, 2022

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.