Configuring Windows System to Allow/Accepts Powershell commands from Remote Systems

When you try to execute a PowerShell command on a remote computer and you receive below error message stating that connection to remote computer failed.

PS C:> Invoke-Command -ComputerName "TestSrv" -ScriptBlock {$env:computername}
[TestSrv] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM.
If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

PS C:>

 

This indicates that the WinRM service is not configured on the remote computer to which you  are trying to connect to. To enable remote connections, you need to run through below command which will install and configures the WinRM service.  Since then you’ll be able to run the commands remotely.

 

PS C:> winrm quickconfig
WinRM is not set up to receive requests on this machine.
The following changes must be made:

Set the WinRM service type to delayed auto start.
Start the WinRM service.

Make these changes [y/n]? y

WinRM has been updated to receive requests.

WinRM service type changed successfully.
WinRM service started.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
Enable the WinRM firewall exception.

Make these changes [y/n]? y

WinRM has been updated for remote management.

Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
WinRM firewall exception enabled.
PS C:>

Leave a Reply

Your email address will not be published. Required fields are marked *