Home » PowerShell » PowerShell – Enable-PSRemoting for Remote Commands

PowerShell – Enable-PSRemoting for Remote Commands

PowerShell remoting features allows to configure computers to receive remote commands. Administrator can run commands on remote systems.

The Enable-PSRemoting cmdlet configures the computers to receive PowerShell remote commands. PowerShell remoting is enabled by default on Windows server platforms. However, PSRemoting needs to be enabled using Enable-PSRemoting on other versions of Windows.

PowerShell - Enable-PSRemoting
PowerShell – Enable-PSRemoting

In this tutorial, I will explain you how to PowerShell Enable-PSRemoting and use remoting features on Windows Server system.

PowerShell Enable-PSRemoting

Cmdlet: Enable-PSRemoting

Description: Configure computers to receive remote commands.

Syntax:

Enable-PSRemoting
      [-Force]
      [-SkipNetworkProfileCheck]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Parameters:

-Force : Suppress all user prompts.

-SkipNetworkProfileCheck : It enable psremoting on Windows clients system when the computer is on public network. This parameter enables firewall rule on Windows client system to receive remote commands from same local subnet computers. Enable-PSRemoting cmdlet enable firewall rule.

If you want to enable remote access to commands from all public networks, use Set-NetFirewallRule cmdlet available in NetSecurity module.

-Confirm – prompt for confirmation before execution of command

-whatIf – It describe the command result if command runs.

Do you know: How to use cat command in windows!

Enable-PSRemoting on Local System

PSRemoting feature is by default enable on Windows Server 2012, Windows Server 2016 or newer version of Windows OS server system.

PowerShell Tip: Enable-PSRemoting PowerShell feature not enabled as by default on Windows clients such as Windows 10 or earlier version of Windows OS system.

To run Enable-PSRemoting cmdlet, Start PowerShell using run as administrator.

PS C:\> Enable-PSRemoting 

When we run command Enable-PSRemoting PowerShell cmdlet, it runs multiple operations in the background.

  • Starts the Windows Remote Management (WinRM) service
  • Sets WinRM service startup type as Automatic
  • Creates a listener to accepts on any IP address
  • Enable a firewall exceptions for WS management
  • Create PowerShell session endpoint configuration
  • Enable all session configurations.
  • Set all sessions configuration to allow remote access
  • Restart Windows Remote Management (WinRM) service to apply above changes.

Enable-PSRemoting reboot the system and setup firewall rule to allow remote commands.

PowerShell Tip: How to get remote printer properties in PowerShell!

Configure computer to receive command without confirmation prompt

Using Enable-PSRemoting -Force parameter suppress the confirmation prompt.

PS C:\> Enable-PSRemoting -Force

Above command runs only on non-public network.

If you want to enable psremoting on public network, you can use -SkipNetProfileCheck parameter

PS C:\> Enable-PSRemoting -SkipNetworkProfileCheck -Force

PowerShell Tip: How to get Computer name and Domain using PowerShell!

Enable-PSRemoting Remotely

PowerShell PSRemoting allows you to run commands on remote computers by enabling PSRemoting on local system. However to run a command remotely without PSRemoting, there are different ways to do it using PowerShell.

Let’s understand Enable-PSRemoting on remote computers with examples.

Using PSexec Enable Remote in PowerShell

You can enable PSRemoting on remote computer using PSexec Utility.

Click here to download PSexec utility from Microsoft website and unzip file PSTool.zip into directory.

To run PSexec.exe, open PowerShell run as administrator and navigate to PSTool folder where it has PSexec.exe file.

To enable remoting on remote computer, run below command

psexec.exe \\Corp-201 -s powershell Enable-PSRemoting -Force

Using above command, it will enable PSRemoting on remote system. However, using PSexec not feasible option if you have many computer to enable PSRemoting. It requires to download PSexec.exe utility.

Use PowerShell Telnet or telnet alternatives to ping remote computer over specified port.

PowerShell Tip: Best way to download zip file using PowerShell!

Using WMI

Using PowerShell Invoke-CimMethod cmdlet to connect to remote computer over DCOM.

WMI has a Win32_Process classes that allows to invoke process. Using Invoke-CimMethod, it connect to remote computer, enabling PSRemoting command.

Using Group Policy

Best feasible way to enable WinRM service on across many computers is to use Group Policy. Using Group Policy, you can create single group policy and apply policy across most of the computers in one go.

To use Group Policy to enable WinRM service, follow below given steps

  • Enable WinRM Service
  • Set WS-Management service to Automatic Startup
  • Configure and Open Firewall port for WinRM service
  • Create WinRM listener

PowerShell Tip: Use Test-Connection to ping multiple computers in PowerShell!

Conclusion

I hope you find above article on PowerShell Enable-PSRemoting useful. You can enable psremoting locally and configure computer to receive command without prompt using -Force parameter.

Enabling PSRemoting remotely enables you to run commands on remote system without PSRemoting by using Psexec utility, WMI and using Group policy method to apply policy across thousands of computer at once to receive command.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment