What is PSRemoting or PowerShell Remoting and how to Enable PS Remoting

PSRemoting or PowerShell Remoting is a PowerShell based remoting which allows you to connect to one or thousands of remote computers and execute commands. PSRemoting allows you to sit at one place and execute commands on remote machine as if you are executing physically on the servers.

In this tutorial you will learn what is PS Remoting that is PowerShell Remoting and how to enable PowerShell Remoting locally and on remote machines.

Table of Content

  1. What is PSRemoting or PowerShell Remoting?
  2. Prerequisites
  3. How to Enable PS Remoting Locally on system?
  4. How to Enable PS Remoting on remote system?
  5. Conclusion

What is PSRemoting or PowerShell Remoting?

PowerShell Remoting is a feature of PowerShell. With PowerShell Remoting you can connect with a single or tons of servers at a single time.

WS-Management or Web services management or WS-Man provides a common way for systems to access and exchange management information across the IT infrastructure.

Microsoft implemented WS-Management or Web services management or WS-Man in WinRM that is Windows Remote Management that allows hardware and operating systems, from different vendors to connect to each other. For WinRM to obtain data from remote computers, you must configure a WinRM listener. WinRM listener can work on both HTTP or HTTPS Protocols.

When PowerShell Remoting takes place between two servers that is one server try to run commands remotely on other server, the source server connects to destination server on WinRM Listener.

How to check WinRM listeners on Windows Host?

To check the WinRM listeners on windows host use the following command

 winrm e winrm/config/listener

Prerequisites

  • Make sure you windows machine with PowerShell 7 installed . If you don’t have, Install it from here.

How to Enable PS Remoting Locally on system?

There are two ways in which you can enable PSRemoting on the local machine.

Use Enable-PSRemoting to Enable PS Remoting Locally on system

  • Invoke the command Enable-PSRemoting and this performs the following function
    • WinRM service is started
    • Creates listener on 5985 for HTTP
    • Registers and Enable PowerShell sessions
    • Set PowerShell sessions to allow remote sessions.
    • Restarts WinRM server

Enable-PSRemoting  # By Default its enabled in Windows
  • On a Server OS, like Windows Server 2019, the firewall rule for Public networks allows on remote connections from other devices on the same network. On a client OS, like Windows 10, you will receive an error stating that you are a public network.
Command Ran on Windows 2019 server
Command Ran on Windows 10 Machine
  • If you want to ignore the Error message because of Network Profile on client like windows 10 use the following command
Enable-PSRemoting -SkipNetworkProfileCheck

Use WinRM to Enable PS Remoting Locally on system

  • We can use WinRM quickconfig command as well to enable PS Remoting on local machine
winrm quickconfig

How to Enable PS Remoting on remote system?

There are two ways in which you can enable PSRemoting on the remote machine.

Use PS exec to Enable PS Remoting on remote system

  • Using PS exec you can run command on remote machine after connecting to remote machine. When you run PS exec command , it initialize the PowerShell session on remote machine and then run the command.
.\psexec.exe \\3.143.113.23 -h -s powershell.exe Enable-PSRemoting -Force # 3.143.113.23 is remote machine's IP address

Use WMI to Enable PS Remoting on remote system

Using PowerShell and the Invoke-CimMethod cmdlet. Using the Invoke-CimMethod cmdlet, you can instruct PowerShell to connect to the remote computer over DCOM and invoke methods.

$SessionArgs = @{
     ComputerName  = 'WIN-U22NTASS3O7'
     Credential    = Get-Credential
     SessionOption = New-CimSessionOption -Protocol Dcom
 }
 $MethodArgs = @{
     ClassName     = 'Win32_Process'
     MethodName    = 'Create'
     CimSession    = New-CimSession @SessionArgs
     Arguments     = @{
         CommandLine = "powershell Start-Process powershell -ArgumentList 'Enable-PSRemoting -Force'"
     }
 }
 Invoke-CimMethod @MethodArgs

Conclusion

In this tutorial, you have learned what is PSRemoting and how to enable PSRemoting with various methods locally on the machine as well as remotely on the machine. This will give you great opportunity to automate with various remote machines together.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s