Connect to Windows VMs using PowerShell

Windows

This document describes how to connect to a Windows virtual machine (VM)instance by using PowerShell.

Note: When a user connects to a VM, that user can use all of the IAM permissions granted to the service account attached to the VM.

Before you begin

Connect using PowerShell

If you have a Windows workstation with PowerShell, you can connect to yourWindows Server instances through a remote PowerShell session.

  1. If you have not created a username and password on the remote Windowsinstance yet,create or reset your Windows password.

  2. Add a firewall rule that opens port5986 ontheGoogle Cloud VPC network where yourWindows Server instance is located.

  3. On your local workstation, open the PowerShell terminal.

  4. Optional: You can initialize a variable to hold your user credentialsso you do not need to enter them each time you connect to the instance.If you skip this step, you receive a prompt for your username and passwordlater.

    $credentials = Get-Credential
  5. Choose whether you want toestablish an interactive Powershell session, orinvoke commands on your Windows Server VM remotely.

Establish an interactive PowerShell session

To establish a PowerShell session, run the following command:

Enter-PSSession -ComputerNameIP_ADDRESS -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials

ReplaceIP_ADDRESS with the external IP address,DNS name, or Windows computer name for the instance to which you want toconnect.

Note: You can find the external IP address of your Windows instance either inthe Google Cloud console on theVM Instances page, or in the Google Cloud CLI by runninggcloud compute instances list.

After you connect, the command prompt changes to include the IP address of theremote Windows instance. You can now use the terminal to run PowerShellcommands on the remote Windows Server instance.

Invoke commands on your Windows Server VM remotely

As an alternative to theEnter-PSSession command, you can runInvoke-Command with the-ScriptBlock flag to execute PowerShell commands on the remoteinstance without establishing an interactive session.

Invoke-Command -ComputerNameIP_ADDRESS -ScriptBlock {SCRIPT } -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials

Replace the following:

  • IP_ADDRESS: the IP address, DNS name, or Windowscomputer name for the instance to which you want to connect.
  • SCRIPT: one or more commands to run on the remoteinstance. For example, specifyGet-EventLog -log "Windows PowerShell" toget a list of log events.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.