Conectar-se às VMs do Windows usando o PowerShell.
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Windows
Este documento descreve como se conectar a uma instância de máquina virtual (VM) do Windows usando o PowerShell.
Antes de começar
Configure a autenticação, caso ainda não tenha feito isso.
A autenticação verifica sua identidade para acesso a serviços e APIs do Google Cloud . Para executar
códigos ou amostras de um ambiente de desenvolvimento local, autentique-se no
Compute Engine selecionando uma das seguintes opções:
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
Instale a CLI do Google Cloud.
Após a instalação,
inicialize a CLI do Google Cloud executando o seguinte comando:
Se você tem uma estação de trabalho do Windows com o PowerShell, pode se conectar a instâncias do Windows Server por meio de uma sessão remota do PowerShell.
Na estação de trabalho local, abra o terminal do PowerShell.
Opcional: inicialize uma variável para manter suas credenciais de usuário
e não ter de digitá-las todas as vezes que você se conectar à instância.
Se você pular esta etapa, receberá uma solicitação de nome de usuário e senha depois.
Substitua IP_ADDRESS pelo endereço IP externo,
o nome DNS ou o nome do computador Windows da instância à que você quer se
conectar.
Após a conexão, o prompt de comando é alterado para incluir o endereço IP da
instância remota do Windows. Use o terminal para executar comandos do
PowerShell na instância remota do Windows Server.
Invocar comandos na VM do Windows Server remotamente
Como alternativa ao comando Enter-PSSession, execute
Invoke-Command
com a sinalização -ScriptBlock para executar comandos do PowerShell na instância
remota sem estabelecer uma sessão interativa.
IP_ADDRESS: o endereço IP, o nome do DNS ou o nome do computador
Windows da instância à que você quer se conectar.
SCRIPT: um ou mais comandos a executar na instância
remota. Por exemplo, especifique Get-EventLog -log "Windows PowerShell" para receber uma lista de eventos de registro.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 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)."]]