Verbindung zu Windows-VMs über PowerShell herstellen.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Windows
In diesem Dokument wird beschrieben, wie Sie mithilfe von PowerShell eine Verbindung zu einer Windows-VM-Instanz herstellen.
Hinweise
Richten Sie die Authentifizierung ein, falls Sie dies noch nicht getan haben.
Bei der Authentifizierung wird Ihre Identität für den Zugriff auf Google Cloud -Dienste und APIs überprüft. Zum Ausführen von Code oder Beispielen aus einer lokalen Entwicklungsumgebung können Sie sich so bei Compute Engine authentifizieren:
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
Installieren Sie die Google Cloud CLI.
Initialisieren Sie die Google Cloud CLI nach der Installation mit dem folgenden Befehl:
Wenn Sie eine Windows-Workstation mit PowerShell haben, können Sie über eine Remote-PowerShell-Sitzung eine Verbindung zu Ihren Windows Server-Instanzen herstellen.
Öffnen Sie das PowerShell-Terminal in Ihrer lokalen Workstation.
Alternativ können Sie eine Variable initialisieren, die Ihre Anmeldedaten aufnimmt, damit Sie diese nicht jedes Mal eingeben müssen, wenn Sie eine Verbindung zu der Instanz herstellen.
Wenn Sie diesen Schritt überspringen, werden Sie später dazu aufgefordert, Ihren Nutzernamen und Ihr Passwort einzugeben.
Ersetzen Sie IP_ADDRESS durch die externe IP-Adresse, den DNS-Namen oder den Windows-Computernamen der Instanz, zu der Sie eine Verbindung herstellen möchten.
Wenn die Verbindung hergestellt wurde, ändert sich die Eingabeaufforderung und enthält nun die IP-Adresse der Remoteinstanz von Windows Server. Sie können das Terminal nun nutzen, um PowerShell-Befehle auf der Remoteinstanz von Windows Server auszuführen.
Befehle per Remote-Zugriff auf der Windows Server-VM aufrufen
Anstelle des Befehls Enter-PSSession können Sie auch Invoke-Command mit dem Flag -ScriptBlock ausführen. Dann werden PowerShell-Befehle auf der Remoteinstanz ausgeführt, ohne eine interaktive Sitzung einzurichten.
IP_ADDRESS ist die IP-Adresse, der DNS-Name oder der Windows-Computername für die Instanz, zu der Sie eine Verbindung herstellen möchten.
SCRIPT ist mindestens ein Befehl, der auf der Remote-Instanz ausgeführt werden soll. Geben Sie zum Beispiel Get-EventLog -log "Windows PowerShell" an, um eine Liste der Logereignisse abzurufen.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]