0
0
PowershellHow-ToBeginner · 3 min read

How to Use Enter-PSSession in PowerShell for Remote Sessions

Use Enter-PSSession in PowerShell to start an interactive remote session on a target computer. You specify the remote computer name or IP with the -ComputerName parameter, and then run commands as if you were on that machine.
📐

Syntax

The basic syntax of Enter-PSSession lets you connect to a remote computer interactively.

  • Enter-PSSession -ComputerName <NameOrIP>: Connects to a remote computer by name or IP.
  • -Credential <UserCredential>: Optional. Use this to specify a different user account for the remote session.
  • -SessionOption <SessionOption>: Optional. Customize session settings like timeouts.
powershell
Enter-PSSession -ComputerName <NameOrIP> [-Credential <UserCredential>] [-SessionOption <SessionOption>]
💻

Example

This example shows how to start a remote session on a computer named Server01. After running the command, your prompt changes to indicate you are connected remotely. You can then run commands on Server01 as if you were logged in there.

powershell
Enter-PSSession -ComputerName Server01
Output
[Server01]: PS C:\Users\YourUser>
⚠️

Common Pitfalls

Common mistakes when using Enter-PSSession include:

  • Not enabling PowerShell remoting on the remote computer. Run Enable-PSRemoting on the target machine first.
  • Firewall blocking the connection. Make sure port 5985 (HTTP) or 5986 (HTTPS) is open.
  • Using incorrect credentials or forgetting to specify -Credential when needed.
  • Trying to connect to a computer that does not allow remote sessions or is offline.

Example of wrong and right usage:

Enter-PSSession -ComputerName Server01
# Might fail if credentials are needed

$cred = Get-Credential
Enter-PSSession -ComputerName Server01 -Credential $cred
# Correct way with credentials
📊

Quick Reference

ParameterDescription
-ComputerNameName or IP of the remote computer to connect to
-CredentialUser credentials for authentication on the remote machine
-SessionOptionAdvanced options like timeouts and proxy settings
-ConfigurationNameSpecify a session configuration on the remote computer
-PortSpecify a custom port for the connection

Key Takeaways

Use Enter-PSSession to start an interactive remote PowerShell session on another computer.
Always ensure PowerShell remoting is enabled and firewall ports are open on the remote machine.
Use the -Credential parameter to provide alternate user credentials if needed.
Your prompt changes to show the remote computer name when connected.
Exit the session with the Exit-PSSession command or Ctrl+D.