{"id":2504,"date":"2013-11-29T00:01:00","date_gmt":"2013-11-29T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/11\/29\/remoting-week-non-domain-remoting\/"},"modified":"2013-11-29T00:01:00","modified_gmt":"2013-11-29T00:01:00","slug":"remoting-week-non-domain-remoting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/remoting-week-non-domain-remoting\/","title":{"rendered":"Remoting Week: Non-Domain Remoting"},"content":{"rendered":"<p><strong>Summary<\/strong>: Richard Siddaway explains how to use Windows PowerShell remoting to access machines that aren&rsquo;t in your domain.\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Hey, Scripting Guy! I&rsquo;ve just starting learning Windows PowerShell, and I understand how to use it as a scripting language and shell on the local machine. How do I work with remote machines?\n&mdash;AP\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Hello AP,\nHonorary Scripting Guy, Richard Siddaway, here today filling in for my good friend, The Scripting Guy. This is the final part of a series of five posts about remoting. To catch up on the previous posts, see:<\/p>\n<ol>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/11\/25\/remoting-week-remoting-recap.aspx\" target=\"_blank\">Remoting Recap<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/11\/26\/remoting-week-remoting-sessions-in-powershell.aspx\" target=\"_blank\">Remoting Sessions<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/11\/27\/remoting-week-configuring-remoting.aspx\" target=\"_blank\">Configuring Remoting<\/a><\/li>\n<li><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/11\/28\/remoting-week-remoting-security.aspx\" target=\"_blank\">Remoting Security<\/a><\/li>\n<\/ol>\n<p>So far in this series, you have seen how to perform ad hoc remoting to systems by using the <strong>ComputerName<\/strong> parameter on various cmdlets. This leads into Windows PowerShell remoting sessions where you create a persistent connection to one or more remote machines. You can use that connection to run multiple commands, and only set up and tear down the connection once, instead of once per command.\nAny remote connectivity system needs to be secure and that is certainly true of Windows PowerShell remoting. In the third part of the series, you saw how HTTPS can be used to secure traffic between the remote system and your administration machine. You also saw how the configuration of the endpoints can be modified to give you more control and lock down the endpoint.\nCustom endpoints can be used to control who can access the endpoint and what they can do. This includes the Windows PowerShell language features and the cmdlets that are available. You can control a range; for example, you can make available the full language and all the installed cmdlets, or you can create a situation where the admin who is connecting to that endpoint can&rsquo;t use the Windows PowerShell language and can only run a hand full of cmdlets. You can connect to that endpoint by using the Windows PowerShell tools, or you can use Windows PowerShell Web Access to give you a Windows PowerShell session that is hosted in your browser by accessing that endpoint.\nIn all of these examples, the assumption is that you are remoting within the domain. You may think that Windows PowerShell Web Access doesn&rsquo;t fit this model, but the Windows PowerShell Web Access server may be in the domain, so the remoting sessions are between machines in the same domain.\nWhat about the situation where the machines aren&rsquo;t in the same domain? You can recognize three broad scenarios for non-domain remoting:<\/p>\n<ol>\n<li>Remoting into a domain<\/li>\n<li>Remoting across domains<\/li>\n<li>Remoting in workgroups<\/li>\n<\/ol>\n<p>Remember that you need network connectivity to the remote machine over the ports that WSMAN will be using. The defaults are HTTP over port 5985 or HTTPS over port 5986.\nYou have already seen one way to solve the issues around options 1 and 2: use Windows PowerShell Web Access.&nbsp; It provides a gateway into the domain that can be used to easily access remoting endpoints within that domain in a secure manner.\nIf the domain to which you are remoting is in the same forest, your environment may be configured to allow the use of your standard credentials. If not, you are back to a situation that can span all three options: you need to remote to a system that isn&rsquo;t in your current domain. Even the workgroup situation can be regarded as a special case in this scenario.\nSo what happens if you try to remote to a machine that isn&rsquo;t in your domain?<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $cred = Get-Credential<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $sess = New-PSSession -ComputerName server02<\/p>\n<p style=\"padding-left: 30px\">New-PSSession : [server02] Connecting to remote server server02 failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help<\/p>\n<p style=\"padding-left: 30px\">config. For more information, see the about_Remote_Troubleshooting Help topic.<\/p>\n<p style=\"padding-left: 30px\">At line:1 char:9<\/p>\n<p style=\"padding-left: 30px\">+ $sess = New-PSSession -ComputerName server02<\/p>\n<p style=\"padding-left: 30px\">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : OpenError: (System.Manageme&#8230;.RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; gTransportException<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed\nTrying to use an IP address such as the following will generate a similar error:<\/p>\n<p style=\"padding-left: 30px\">$sess = New-PSSession -ComputerName 10.10.54.201 -Credential $cred\nThe issue is that the client machine and the remote machine are not able to mutually authenticate as they would within a domain. The error messages are useful in that they provide a couple of possible answers:<\/p>\n<ul>\n<li>Install a SSL certificate, and use HTTPS to connect to the remote machine.<\/li>\n<li>Add the machine to the trusted hosts list.<\/li>\n<\/ul>\n<p>I discussed using HTTPS in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/11\/27\/remoting-week-configuring-remoting.aspx\" target=\"_blank\">Configuring Remoting<\/a>, so this time I will solve the issue by using the trusted hosts list. The trusted hosts list effectively bypasses the mutual authentication at the machine level. By placing a system in the list, you are explicitly stating that you trust the system and that it is safe to connect to that system.\nYou can view the contents of the trusted hosts list by accessing the WSMAN provider:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Get-Item -Path WSMan:localhostClientTrustedHosts<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; WSManConfig: Microsoft.WSMan.ManagementWSMan::localhostClient<\/p>\n<p style=\"padding-left: 30px\">Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SourceOfValue&nbsp;&nbsp; Value<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">System.String&nbsp;&nbsp; TrustedHosts\nIn this case, the list is empty. Remember that you can also connect to the WSMAN provider on a remote machine by using <strong>Connect-WSMan<\/strong> and examine the settings there. Another way is to use the WSMAN cmdlets:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Get-WSManInstance -ResourceURI winrm\/config\/client<\/p>\n<p style=\"padding-left: 30px\">cfg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : http:\/\/schemas.microsoft.com\/wbem\/wsman\/1\/config\/client<\/p>\n<p style=\"padding-left: 30px\">lang&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : en-GB<\/p>\n<p style=\"padding-left: 30px\">NetworkDelayms&nbsp;&nbsp; : 5000<\/p>\n<p style=\"padding-left: 30px\">URLPrefix&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : wsman<\/p>\n<p style=\"padding-left: 30px\">AllowUnencrypted : false<\/p>\n<p style=\"padding-left: 30px\">Auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Auth<\/p>\n<p style=\"padding-left: 30px\">DefaultPorts&nbsp;&nbsp;&nbsp;&nbsp; : DefaultPorts<\/p>\n<p style=\"padding-left: 30px\">TrustedHosts&nbsp;&nbsp;&nbsp;&nbsp; :\n<strong>Set-Item<\/strong> can be used to modify the trusted hosts list:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Set-Item -Path WSMan:localhostClientTrustedHosts -Value &#8216;server02&#8217;<\/p>\n<p style=\"padding-left: 30px\">WinRM Security Configuration.<\/p>\n<p style=\"padding-left: 30px\">This command modifies the TrustedHosts list for the WinRM client. The computers in the TrustedHosts list might not be authenticated. The client might send credential information to these computers. Are you sure that you want to modify this list?<\/p>\n<p style=\"padding-left: 30px\">[Y] Yes&nbsp; [N] No&nbsp; [S] Suspend&nbsp; [?] Help (default is &#8220;Y&#8221;): Y\nThe WSMAN provider adds <strong>&ndash;Concatenate<\/strong> as dynamic parameter to <strong>Set-Item<\/strong>.&nbsp; You can also use <strong>&ndash;Force<\/strong> to bypass the confirm message:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Get-Item -Path WSMan:localhostClientTrustedHosts | fl Name, Value<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp; : TrustedHosts<\/p>\n<p style=\"padding-left: 30px\">Value : server02<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Set-Item -Path WSMan:localhostClientTrustedHosts -Value &#8216;10.10.54.201&#8217; -Concatenate -Force<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Get-Item -Path WSMan:localhostClientTrustedHosts | fl Name, Value<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp; : TrustedHosts<\/p>\n<p style=\"padding-left: 30px\">Value : server02,10.10.54.201\nAgain the WSMAN cmdlets are an alternative:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $hosts = &#8216;server02,10.10.54.201&#8217;<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Set-WSManInstance -ResourceURI winrm\/config\/client -ValueSet @{TrustedHosts=$hosts}<\/p>\n<p style=\"padding-left: 30px\">cfg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : http:\/\/schemas.microsoft.com\/wbem\/wsman\/1\/config\/client<\/p>\n<p style=\"padding-left: 30px\">lang&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : en-GB<\/p>\n<p style=\"padding-left: 30px\">NetworkDelayms&nbsp;&nbsp; : 5000<\/p>\n<p style=\"padding-left: 30px\">URLPrefix&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : wsman<\/p>\n<p style=\"padding-left: 30px\">AllowUnencrypted : false<\/p>\n<p style=\"padding-left: 30px\">Auth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Auth<\/p>\n<p style=\"padding-left: 30px\">DefaultPorts&nbsp;&nbsp;&nbsp;&nbsp; : DefaultPorts<\/p>\n<p style=\"padding-left: 30px\">TrustedHosts&nbsp;&nbsp;&nbsp;&nbsp; : server02,10.10.54.201\nWhen you have the correct values in the trusted host list, you need to define a credential to access that machine. It can be a local domain or machine, depending on the scenario. If it&rsquo;s a local machine, remember to present <strong>UserId<\/strong> as <strong>&lt;machine name&gt;\/userid<\/strong>. Otherwise, Windows PowerShell will think the credential is on your local machine.<\/p>\n<p style=\"padding-left: 30px\">$cred = Get-Credential\nYou then create a session to that remote machine as normal, and use the credential you created:<\/p>\n<p style=\"padding-left: 30px\">$sess = New-PSSession -ComputerName server02 -Credential $cred<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session $sess -ScriptBlock{Get-Service}\nNormally, you can&rsquo;t create remoting sessions to IP addresses. But because the IP address is in the trusted hosts list, you can do this:<\/p>\n<p style=\"padding-left: 30px\">$sess2 = New-PSSession -ComputerName 10.10.54.201 -Credential $cred<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session $sess2 -ScriptBlock{Get-Service}\nYou may see references on the Internet to having a single value in the trusted hosts list of <strong>*<\/strong>. This acts as a wildcard character that says trust every machine, everywhere. I have one simple piece of advice: Don&rsquo;t do it! I don&rsquo;t do that in a lab environment, not to mention in production.\nOne possibility to consider is to script the setting of the trusted hosts list and then script the removal of the values after you have done your work. This reduces the security impact of using the trusted hosts file.\nIf you are working wholly within your network, using the trusted hosts file is a workable solution. If you are accessing a remote machine from outside your environment, consider using Windows PowerShell Web Access.\nThis concludes my mini-series about Windows PowerShell remoting. You have seen various ways that you can connect to a remote machine, and I made recommendations as to when particular techniques should be used. More information is available in the Windows PowerShell Help files, and you can discover further details about configuring remoting and some other edge cases in Chapter 10 of <a href=\"http:\/\/www.manning.com\/jones2\/\" target=\"_blank\">PowerShell in Depth<\/a> by myself, Don Jones, and Jeffery Hicks.\nBye for now.\n~Richard\nThanks, Richard! This has been an awesome series.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Richard Siddaway explains how to use Windows PowerShell remoting to access machines that aren&rsquo;t in your domain. &nbsp;Hey, Scripting Guy! I&rsquo;ve just starting learning Windows PowerShell, and I understand how to use it as a scripting language and shell on the local machine. How do I work with remote machines? &mdash;AP &nbsp;Hello AP, Honorary [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[57,189,4,45],"class_list":["post-2504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-remoting","tag-richard-siddaway","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Richard Siddaway explains how to use Windows PowerShell remoting to access machines that aren&rsquo;t in your domain. &nbsp;Hey, Scripting Guy! I&rsquo;ve just starting learning Windows PowerShell, and I understand how to use it as a scripting language and shell on the local machine. How do I work with remote machines? &mdash;AP &nbsp;Hello AP, Honorary [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2504"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}