PowerShell Remoting allows you to connect to a remote shell on another Windows computer.
The server is the Windows computer that will host the shell, and that you will connect to. The client is the Windows computer that will create the connection, on which you will see and interact with the shell.
These steps assume a workgroup with Windows 10 or Server 2016 or later on the server, and Windows 7 or later on the client. It assumes that the client is running with a user account that also exists on the server with the same password. Neither the server nor the client need to be joined to a domain or using Kerberos.
- Workgroup, not domain
- Server operating system is Windows 10, Server 2016, or later
- Client operating system is Windows 7, Server 2008 R2, or later
- Client's user account also exists on server with same username and password
Run these commands in administrator PowerShells.
- Turn on PowerShell Remoting.
This automatically configures WinRM service, firewall, and other components).
Enable-PSRemoting
- Trust your client computer, or trust any client computer.
# trust client's hostname Set-Item wsman:\localhost\client\trustedhosts myclienthostname # or trust client's static IP address Set-Item wsman:\localhost\client\trustedhosts 192.168.1.100 # or trust any client Set-Item wsman:\localhost\client\trustedhosts *
- Restart the WinRM service for trust settings to take effect.
Restart-Service WinRM
- Add the user account to the group that allows remote sessions.
- Open Local Users and Groups (
lusrmgr.msc
). - Make the desired user a Member Of the
Remote Management Users
group.
- Open Local Users and Groups (
- Trust your server computer, or trust any server computer.
# trust server's hostname Set-Item wsman:\localhost\client\trustedhosts myserverhostname # or trust server's static IP address Set-Item wsman:\localhost\client\trustedhosts 192.168.1.101 # or trust any server Set-Item wsman:\localhost\client\trustedhosts *
- When it prompts you to ask if you're sure, or if you want to start the
WSMan
service, pressy
.
If you get InvalidOperationException
errors when you run this Set-Item
cmdlet, try running Restart-Service WinRM
.
Ensure the server's WinRM server is accessible to the client.
Test-WSMan myserverhostname
This should print out an object with wsmid
and other properties.
Connect to a remote session.
Enter-PSSession myserverhostname
This will allow you to easily launch a remote session by typing the token of your choice.
- Create a new empty PowerShell profile file, if it doesn't already exist, in
%USERPROFILE%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
(for PowerShell Core), or%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
(for Windows PowerShell). - Create a function to enter the session, and an alias for that function.
function Enter-PSSession-MyServer { Enter-PSSession myserverhostname } Set-Alias -Name myserver -Value Enter-PSSession-MyServer
- Open a PowerShell window and type
myserver
to connect.
This will allow you to easily launch a remote session without having to type any commands.
- Create a new shortcut wherever you want, like the Start Menu or Desktop.
- Set the Target to
powershell.exe -NoExit -Command "& Enter-PSSession myserverhostname"
See also SSH.