Stay organized with collections
Save and categorize content based on your preferences.
Windows
This document describes how to connect to a Windows virtual machine (VM)
instance by using PowerShell.
Before you begin
If you haven't already, set up authentication.
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:
On your local workstation, open the PowerShell terminal.
Optional: You can initialize a variable to hold your user credentials
so 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 password
later.
Replace IP_ADDRESS with the external IP address,
DNS name, or Windows computer name for the instance to which you want to
connect.
After you connect, the command prompt changes to include the IP address of the
remote Windows instance. You can now use the terminal to run PowerShell
commands on the remote Windows Server instance.
Invoke commands on your Windows Server VM remotely
As an alternative to the Enter-PSSession command, you can run
Invoke-Command
with the -ScriptBlock flag to execute PowerShell commands on the remote
instance without establishing an interactive session.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003eThis document guides you through connecting to a Windows virtual machine (VM) instance using PowerShell, enabling remote management and command execution.\u003c/p\u003e\n"],["\u003cp\u003eBefore connecting, ensure you have set up authentication via the Google Cloud CLI or are using the Google Cloud console, and have created or reset your Windows password on the remote instance.\u003c/p\u003e\n"],["\u003cp\u003eConnecting to a Windows Server instance requires opening port 5986 in your Google Cloud VPC network's firewall rules, in order to accept remote PowerShell connections.\u003c/p\u003e\n"],["\u003cp\u003eYou can establish either an interactive PowerShell session using \u003ccode\u003eEnter-PSSession\u003c/code\u003e or remotely invoke commands on the VM without an interactive session by using the \u003ccode\u003eInvoke-Command\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eWhen a user connects to a VM, they can utilize all IAM permissions granted to the service account attached to that specific VM.\u003c/p\u003e\n"]]],[],null,["# Connect to Windows VMs using PowerShell\n\nWindows\n\n*** ** * ** ***\n\nThis document describes how to connect to a Windows virtual machine (VM)\ninstance by using PowerShell.\n| **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.\n\nBefore you begin\n----------------\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). 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:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\nConnect using PowerShell\n------------------------\n\nIf you have a Windows workstation with PowerShell, you can connect to your\nWindows Server instances through a remote PowerShell session.\n\n1. If you have not created a username and password on the remote Windows\n instance yet,\n [create or reset your Windows password](/compute/docs/instances/windows/creating-passwords-for-windows-instances).\n\n2. [Add a firewall rule](/vpc/docs/using-firewalls) that opens port `5986` on\n the [Google Cloud VPC network](/vpc/docs) where your\n Windows Server instance is located.\n\n3. On your local workstation, open the PowerShell terminal.\n\n4. Optional: You can initialize a variable to hold your user credentials\n so you do not need to enter them each time you connect to the instance.\n If you skip this step, you receive a prompt for your username and password\n later.\n\n ```\n $credentials = Get-Credential\n ```\n5. Choose whether you want to\n [establish an interactive Powershell session](#interactive), or\n [invoke commands on your Windows Server VM remotely](#invoke-remotely).\n\n### Establish an interactive PowerShell session\n\nTo establish a PowerShell session, run the following command: \n\n```\nEnter-PSSession -ComputerName IP_ADDRESS -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials\n```\n\nReplace \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e with the external IP address,\nDNS name, or Windows computer name for the instance to which you want to\nconnect.\n| **Note:** You can find the external IP address of your Windows instance either in the Google Cloud console on the [**VM Instances**](https://console.cloud.google.com/compute/instances) page, or in the Google Cloud CLI by running `gcloud compute instances list`.\n\nAfter you connect, the command prompt changes to include the IP address of the\nremote Windows instance. You can now use the terminal to run PowerShell\ncommands on the remote Windows Server instance.\n\n### Invoke commands on your Windows Server VM remotely\n\nAs an alternative to the `Enter-PSSession` command, you can run\n[`Invoke-Command`](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/invoke-command)\nwith the `-ScriptBlock` flag to execute PowerShell commands on the remote\ninstance without establishing an interactive session. \n\n```\nInvoke-Command -ComputerName IP_ADDRESS -ScriptBlock { SCRIPT } -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eIP_ADDRESS\u003c/var\u003e: the IP address, DNS name, or Windows computer name for the instance to which you want to connect.\n- \u003cvar translate=\"no\"\u003eSCRIPT\u003c/var\u003e: one or more commands to run on the remote instance. For example, specify `Get-EventLog -log \"Windows PowerShell\"` to get a list of log events.\n\nWhat's next\n-----------\n\n- Learn how to [manage access to instances](/compute/docs/instances/managing-instance-access) for multiple users across a project or organization.\n- [Securely connect to VM instances](/solutions/connecting-securely).\n- [Transfer files to your Linux instances](/compute/docs/instances/transfer-files)."]]