Connect to Windows VMs using PowerShell Stay organized with collections Save and categorize content based on your preferences.
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
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
Connect using PowerShell
If you have a Windows workstation with PowerShell, you can connect to yourWindows Server instances through a remote PowerShell session.
If you have not created a username and password on the remote Windowsinstance yet,create or reset your Windows password.
Add a firewall rule that opens port
5986ontheGoogle Cloud VPC network where yourWindows Server instance is located.On your local workstation, open the PowerShell terminal.
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
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.
gcloud 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 $credentialsReplace 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
- Learn how tomanage access to instancesfor multiple users across a project or organization.
- Securely connect to VM instances.
- Transfer files to your Linux instances.
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.