Connecting to Azure Windows VM Using PowerShell

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be able to log in to a Windows machine using PowerShell. Directly from Cloud Shell, you can access a Windows machine without having to establish an RDP connection, log in, and have to navigate the Windows GUI. This creates ease of use and frees up a lot of administrative tasks across multiple VMs for a system administrator.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Connect to Cloud Shell in the Azure Portal
  1. Open a web browser and go to
  2. Use the email and password provided with this hands-on lab to log in to the portal.
  3. Click the Cloud Shell icon in top menu bar to open it.
  4. Select PowerShell.
  5. Click Show advanced settings.
  6. Create a new storage account that is globally unique.
  7. Create a file share named "fileshare".
  8. Click Create storage.
Create a New PowerShell Remoting Session
  1. Create a new PSSession (you can get the <winVM_PUBLIC_IP> from the lab page or the Azure Portal):

    New-PSSession -HostName '<winVM_PUBLIC_IP>' -UserName cloud_user
  2. Enter Get-PSSession to verify that the session has been saved.

  3. Store the session in a variable named $s ($s = Get-PSSession).

Connect to the VM Using PowerShell
  1. Connect to the VM remotely:

    Enter-PSSession -Session $s
  2. Verify that the VM is Windows by calling the variable $PSVersionTable.

Additional Resources

As a Windows administrator of a large organization, you have many Windows servers to manage. You'd like to quickly access these machines without having to memorize machine names or IPs. Furthermore, you'd like to administer these machines remotely. Using PowerShell, you must perform the necessary commands to remotely manage these servers and make your life a lot easier.

The steps to set up OpenSSH on the Windows VM are as follows:

  • Log in to the Windows VM via an RDP session.
  • Open the file sshd_config_replace in the C:Program Datassh directory.
  • Copy the entire contents of sshd_config_replace and paste it in the file sshd_config within the same directory (replacing the contents of ssh_config).
  • Go to the C:UsersPublicDownloads directory and double-click the file pwsh.msi to install PowerShell Core.
  • When the wizard pops up, click Next and check the Enable PowerShell remoting option.
  • Install PowerShell Core and close the wizard.
  • Open Windows PowerShell by clicking on the Windows button and typing "PowerShell".
  • Restart the sshd service with the command Restart-Service sshd.
  • Close the RDP session and return to the Azure Portal.

To consider this lab complete, please perform the following:

  • Log in to the Azure Portal and open a Cloud Shell PowerShell prompt.
  • Establish a new PowerShell remote session.
  • Using the established session, connect to the VM and verify that you are on a Windows VM.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?