{"id":15072,"date":"2019-09-23T07:37:58","date_gmt":"2019-09-23T07:37:58","guid":{"rendered":"https:\/\/www.top-password.com\/blog\/?p=15072"},"modified":"2019-09-23T07:46:51","modified_gmt":"2019-09-23T07:46:51","slug":"run-powershell-commands-on-remote-computer","status":"publish","type":"post","link":"https:\/\/www.top-password.com\/blog\/run-powershell-commands-on-remote-computer\/","title":{"rendered":"Tutorial: Run PowerShell Commands on Remote Computer"},"content":{"rendered":"<p>How can I run a PowerShell script from a remote computer? Are there any basic instructions for getting Powershell remoting to work through WinRM? In this tutorial we&#8217;ll walk you through the steps to run PowerShell commands on a remote computer.<\/p>\n<p>Let&#8217;s say your local PC is called &#8220;<em>PC01<\/em>&#8221; and you&#8217;re going to use PowerShell remoting to manage a remote server called &#8220;<em>Server01<\/em>&#8220;. Before getting started, make sure the network profiles on both PCs are set to either Domain or Private. If your network profile is set to Public, you can change it to Private by following <a href=\"https:\/\/www.top-password.com\/blog\/change-network-location-to-public-or-private-in-windows-10\/\" target=\"_blank\" rel=\"noopener noreferrer\">this article<\/a>.<\/p>\n<p><strong>Part 1: Enable PowerShell Remoting<\/strong><\/p>\n<ol>\n<li>On the remote server, open the PowerShell console as Administrator and run the following command which will start the WinRM service and create a firewall to allow incoming connections.\n<p><code>Enable-PSRemoting -Force<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2019\/09\/enable-powershell-remoting.png\" alt=\"\" width=\"585\" height=\"209\" class=\"alignnone size-full wp-image-15078\" \/>\n<\/li>\n<li>Next, you need to configure the TrustedHosts setting on the remote server so it will trust your local PC &#8220;<em>PC01<\/em>&#8220;. Type the following command and hit Enter.\n<p><code>Set-Item WSMan:\\localhost\\Client\\TrustedHosts -Value \"PC01\" -Force<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2019\/09\/configure-trusted-hosts.png\" alt=\"\" width=\"604\" height=\"119\" class=\"alignnone size-full wp-image-15079\" \/>\n<\/li>\n<li>Restart the WinRM service to apply your new settings.\n<p><code>Restart-Service WinRM<\/code><\/li>\n<\/ol>\n<p><strong>Part 2: Configure Your Local PC<\/strong><\/p>\n<ol>\n<li>On the local PC, open the PowerShell with admin rights and start the WinRM service using this command:\n<p><code>Start-Service WinRM<\/code><\/li>\n<li>Next, you can add the remote server &#8220;<em>Server01<\/em>&#8221; to the TrustedHosts list with the following command, so your local PC will also trust the remote server.\n<p><code>Set-Item WSMan:\\localhost\\Client\\TrustedHosts -Value \"Server01\" -Force<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2019\/09\/restart-winrm.png\" alt=\"\" width=\"556\" height=\"153\" class=\"alignnone size-full wp-image-15080\" \/>\n<\/li>\n<li>Run the following command to restart the WinRM service:\n<p><code>Restart-Service WinRM<\/code><\/li>\n<\/ol>\n<p><strong>Part 3: Test PowerShell Remoting<\/strong><\/p>\n<ol>\n<li>Now when both computers have been configured, you can start a remote session by running the following PowerShell command on your local PC. Remember to replace &#8220;<em>Tom<\/em>&#8221; with the name of your remote server&#8217;s administrator account.\n<p><code>Enter-PSSession -ComputerName Server01 -Credential Tom<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2019\/09\/powershell-credential-request.png\" alt=\"\" width=\"572\" height=\"345\" class=\"alignnone size-full wp-image-15081\" \/>\n<\/li>\n<li>Enter the administrator password when prompted. Now, the session is established, all commands that are being entered in the PowerShell console are executed on the remote computer.\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2019\/09\/run-powershell-command-on-remote-pc.png\" alt=\"\" width=\"572\" height=\"123\" class=\"alignnone size-full wp-image-15086\" \/>\n<\/li>\n<li>To end the interactive session, type this command:<br \/>\n<code>Exit-PSSession<\/code><\/li>\n<\/ol>\n<p>That&#8217;s all!<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How can I run a PowerShell script from a remote computer? Are there any basic instructions for getting Powershell remoting to work through WinRM? In this tutorial we&#8217;ll walk you through the steps to run PowerShell commands on a remote computer. Let&#8217;s say your local PC is called &#8220;PC01&#8221; and you&#8217;re going to use PowerShell [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,10],"tags":[4336,4335,4337],"class_list":["post-15072","post","type-post","status-publish","format-standard","hentry","category-others","category-tips-tricks","tag-enable-powershell-remoting","tag-powershell-connect-to-remote-computer","tag-run-powershell-on-remote-computer"],"_links":{"self":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/15072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/comments?post=15072"}],"version-history":[{"count":11,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/15072\/revisions"}],"predecessor-version":[{"id":15089,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/15072\/revisions\/15089"}],"wp:attachment":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/media?parent=15072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/categories?post=15072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/tags?post=15072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}