Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
After installing the Google Cloud CLI, initialize it 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.
If you have a Windows workstation with PowerShell, you can connect to your Windows Server instances through a remote PowerShell session.
If you have not created a username and password on the remote Windows instance yet, create or reset your Windows password.
Add a firewall rule that opens port 5986
on the Google Cloud VPC network where your Windows Server instance is located.
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.
$credentials = Get-Credential
Choose whether you want to establish an interactive Powershell session, or invoke commands on your Windows Server VM remotely.
To establish a PowerShell session, run the following command:
Enter-PSSession -ComputerName IP_ADDRESS -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials
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.
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.
Invoke-Command -ComputerName IP_ADDRESS -ScriptBlock { SCRIPT } -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck) -Credential $credentials
Replace the following:
IP_ADDRESS
: the IP address, DNS name, or Windows computer name for the instance to which you want to connect.SCRIPT
: 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.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.