{"id":4641,"date":"2009-01-13T02:12:05","date_gmt":"2009-01-13T02:12:05","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/01\/13\/interactive-remoting-in-ctp3\/"},"modified":"2019-02-18T13:12:53","modified_gmt":"2019-02-18T20:12:53","slug":"interactive-remoting-in-ctp3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/interactive-remoting-in-ctp3\/","title":{"rendered":"Interactive remoting in CTP3"},"content":{"rendered":"<p>Today let&#8217;s talk about one of the cool new features of Windows PowerShell V2 &#8211; Interactive Remoting.<\/p>\n<p>Let\u2019s start with an example:<\/p>\n<pre style=\"font-size: 10pt;margin: 20pt 10pt;line-height: normal;font-family: consolas,lucida console,courier new\"><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> $env:COMPUTERNAME # Check local computer name.                                                                      <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">VLADIMIA64                                                                                                              <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> Enter-PSSession Vladimia06 # Remote to other computer.                                                              <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $env:COMPUTERNAME # Check remote computer name.                           <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">Vladimia06                                                                                                              <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $PSVersionTable # Check powershell version on remote computer.            <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">                                                                                                                        <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">Name                           Value                                                                                    <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">----                           -----                                                                                    <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">CLRVersion                     2.0.50727.3521                                                                           <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">BuildVersion                   6.1.7015.0                                                                               <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">PSVersion                      2.0                                                                                      <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">PSCompatibleVersions           {1.0, 2.0}                                                                               <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">                                                                                                                        <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">                                                                                                                        <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; function prompt {} # See how prompt function is always prefixed by [&lt;compu<\/span><br \/><span style=\"background: #012456;color: #eeedf0\">tername&gt;]: in interactive remoting.                                                                                     <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS&gt;Exit-PSSession # Exit remote session.                                                                  <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\">                                                                                                                     <\/span><\/pre>\n<p>As you can see <strong>Enter-PSSession<\/strong> starts interactive remoting session and <strong>Exit-PSSession<\/strong> takes you out of it. The aliases for these commands are <strong>etsn<\/strong> and <strong>exsn<\/strong>. You can also use <strong>exit<\/strong> keyword instead of <strong>Exit-PSSession<\/strong>.<\/p>\n<p>Interactive remoting uses the same remoting infrastructure as other PowerShell remoting cmdlets. WinRM provides the transport and maintains a listener service, which is responsible for creation of the remote PowerShell sessions.<\/p>\n<p>Similar to Invoke-Command, you can use computer name to establish remote connection. In that case remote PSSession is created implicitly for you when you enter and disposed of after you exit.<\/p>\n<p>Alternatively, you can create a persistent session using <strong>New-PSSession<\/strong> command and use it with <strong>Enter-PSSession<\/strong>. In that case the session won\u2019t be closed after you finish and you can enter it multiple times exactly when you need it.<\/p>\n<pre style=\"font-size: 10pt;margin: 20pt 10pt;line-height: normal;font-family: consolas,lucida console,courier new\"><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> $s = nsn vladimia06  # Create a persistent remote session.                                                          <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> etsn $s                                                                                                             <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $x = 123  # Create a variable.                                            <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; exsn                                                                      <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> etsn $s                                                                                                             <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $x # Check that a variable is still there                                 <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">123                                                                                                                     <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">[vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; exsn                                                                      <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> icm $s {$x}  # The variable created in interactive remoting can also be accessed using remote invocation.           <\/span><br \/><span style=\"background: #012456;color: #eeedf0\">123                                                                                                                     <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\"> rsn $s  # Close the remote session.                                                                                 <\/span><br \/><span style=\"background: #012456;color: yellow\">PS&gt;<\/span><span style=\"background: #012456;color: #eeedf0\">                                                                                                                     <\/span><\/pre>\n<p>Note that the variables that are created in remote session won\u2019t be available in your local runspace when you exit. You need to use <strong>Invoke-Command<\/strong> to get them to the client side. The corresponding object will be serialized over the wire and reassembled on the other side. Primitive types will be restored as fully functional \u2018live\u2019 objects, but more complex object will be reduced to deserialized \u2018property bags\u2019. We will talk more on serialization in one of the next posts.<\/p>\n<p>Try it, use it, love it!\n  <br \/>Vladimir Averkin\n  <br \/>Windows PowerShell Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today let&#8217;s talk about one of the cool new features of Windows PowerShell V2 &#8211; Interactive Remoting. Let\u2019s start with an example: PS&gt; $env:COMPUTERNAME # Check local computer name. VLADIMIA64 PS&gt; Enter-PSSession Vladimia06 # Remote to other computer. [vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $env:COMPUTERNAME # Check remote computer name. Vladimia06 [vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $PSVersionTable # Check powershell [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[137,8],"class_list":["post-4641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-ctp3","tag-remoting"],"acf":[],"blog_post_summary":"<p>Today let&#8217;s talk about one of the cool new features of Windows PowerShell V2 &#8211; Interactive Remoting. Let\u2019s start with an example: PS&gt; $env:COMPUTERNAME # Check local computer name. VLADIMIA64 PS&gt; Enter-PSSession Vladimia06 # Remote to other computer. [vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $env:COMPUTERNAME # Check remote computer name. Vladimia06 [vladimia06]: PS C:\\Users\\Vladimia\\Documents&gt; $PSVersionTable # Check powershell [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=4641"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4641\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=4641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}