Enable-PSRemoting

Configure the computer to receive remote commands. Run PowerShell commands on remote computers.

Syntax
      Enable-PSRemoting [-Force] [-SkipNetworkProfileCheck]
         [-Confirm] [-WhatIf] [CommonParameters]

Key:
   -Force
       Suppress all user prompts. By default, you are prompted to confirm each operation.

   -SkipNetworkProfileCheck
       Enable remoting on client versions of Windows when the computer is on a public network.
       This parameter enables a firewall rule for public networks that allows remote access only from
       computers in the same local subnet.
       This parameter has no effect on server versions of Windows, which, by default, have a
       local subnet firewall rule for public networks. If the local subnet firewall rule is disabled on
       a server version of Windows, Enable-PSRemoting re-enables it, regardless of the value of this parameter.
       To remove the local subnet restriction and enable remote access from all locations on public networks,
       use the  Set-NetFirewallRule cmdlet in the NetSecurity module.  (PowerShell 3.0+)

   -confirm
       Prompt for confirmation before executing the command.

   -whatIf
       Describe the command without actually executing it.

Enable-PSRemoting configures a computer to receive PowerShell remote commands sent with WS-Management technology.

To run this cmdlet, start PowerShell with the "Run as administrator" option.

PS Remoting only needs to be enabled once on each computer that will receive commands.
Computers that only send commands do not need to have PS Remoting enabled; because the configuration activates listeners (and starts the WinRM service), it is prudent to run it only where needed.

To run a command on the remote system, use Invoke-Command or Enter-PSSession for multiple commands.

If your computers aren’t on a domain, you’ll need to perform the following extra steps:
On both computers:

Configure the TrustedHosts setting so the computers will trust each other:
Set-Item WSMan:\localhost\client\trustedhosts PC64,PC65,PC66
The comma-separated list can be IP addresses or computer names or even a * wildcard to match all.

run : Restart-Service WinRM

To view the current trusted hosts:
Get-Item WSMan:\localhost\Client\TrustedHosts

Examples

Configure the local computer to receive remote commands:

PS C:\> Enable-PSRemoting

Configure the computer to receive remote commands & suppress user prompts:

PS C:\> Enable-PSRemoting -Force

Configure the remote computer workstation64 to receive remote commands, via psexec. If you are running this from an account which is NOT an administrator of the remote machine, then specify the username/password of an account with admin rights to the remote machine:

PS C:\> psexec \\PC64 -u adminUser64 -p pa$$w0rd -h -d powershell.exe "enable-psremoting -force"

Test that the computer computer64 is setup to receive remote commands:

PS C:\> Test-WsMan PC64

Run a single command on the remote computer using Invoke-Command:

PS C:\> Invoke-Command -ComputerName PC64 -ScriptBlock { Get-ChildItem C:\ } -credential jdoe

Run multiple commands by starting a Remote PowerShell Session:

PS C:\> Enter-PSSession -ComputerName PC64 -Credential AshleyT

“He who lies hid in remote places is a law unto himself” ~ Publilius Syrus

Related PowerShell Cmdlets

How-To: Run a PowerShell script on a remote computer.
Enter-PSSession - Start an interactive session with a remote computer.
Disable-PSRemoting - Prevent remote users from running commands on the local computer.
Test-WSMan - Test if a computer is setup to receive remote commands via the WinRM service.
Invoke-Command - Run commands on local and remote computers.
WINRM - Windows Remote Management .


 
Copyright © 1999-2024 SS64.com
Some rights reserved