{"id":2510,"date":"2013-11-26T00:01:00","date_gmt":"2013-11-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/11\/26\/remoting-week-remoting-sessions\/"},"modified":"2013-11-26T00:01:00","modified_gmt":"2013-11-26T00:01:00","slug":"remoting-week-remoting-sessions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/remoting-week-remoting-sessions\/","title":{"rendered":"Remoting Week: Remoting Sessions"},"content":{"rendered":"<p><strong>Summary<\/strong>: Richard Siddaway explains how to use WindowsPowerShell remoting sessions.\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. But 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 second part of a series of five posts about remoting. The series includes:<\/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>Remoting Sessions<\/li>\n<li>Configuring Remoting<\/li>\n<li>Remoting Security<\/li>\n<li>Non-Domain Remoting<\/li>\n<\/ol>\n<p>In my Remoting Recap post, you saw that you can use <strong>Invoke-Command<\/strong> to send a command to a remote machine over a WSMAN connection, and then receive the results back on your local machine, for example:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -ComputerName $computer -ScriptBlock {Get-Service}\nThis great if you want to send only a single command. But if you have a number of commands, it is more efficient to create a remoting session to the target machine and run the commands over that. You only have one set up and tear down instead of one per command.\nYou get several cmdlets for working with Windows PowerShell remoting sessions:<\/p>\n<ul>\n<li>Connect-PSSession<\/li>\n<li>Disconnect-PSSession<\/li>\n<li>Enter-PSSession<\/li>\n<li>Exit-PSSession<\/li>\n<li>Export-PSSession<\/li>\n<li>Get-PSSession<\/li>\n<li>Import-PSSession<\/li>\n<li>New-PSSession<\/li>\n<li>Receive-PSSession<\/li>\n<li>Remove-PSSession<\/li>\n<\/ul>\n<p>You&rsquo;ll see a number of them in action in this post. The starting point is to create a session that is connected to a remote machine:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $sess = New-PSSession -ComputerName win12r2<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $sess | fl *<\/p>\n<p style=\"padding-left: 30px\">State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Opened<\/p>\n<p style=\"padding-left: 30px\">IdleTimeout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7200000<\/p>\n<p style=\"padding-left: 30px\">OutputBufferingMode&nbsp;&nbsp;&nbsp; : Block<\/p>\n<p style=\"padding-left: 30px\">DisconnectedOn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">ExpiresOn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">ComputerName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : win12r2<\/p>\n<p style=\"padding-left: 30px\">ConfigurationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.PowerShell<\/p>\n<p style=\"padding-left: 30px\">InstanceId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 818369f6-2458-43f0-b6b2-81d8c8be9d34<\/p>\n<p style=\"padding-left: 30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Session2<\/p>\n<p style=\"padding-left: 30px\">Availability&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Available<\/p>\n<p style=\"padding-left: 30px\">ApplicationPrivateData : {DebugMode, DebugStop, PSVersionTable, DebugBreakpointCount}<\/p>\n<p style=\"padding-left: 30px\">Runspace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.RemoteRunspace\nIn this case, I&rsquo;m remoting from a computer running Windows&nbsp;8.1 to a system running Windows Server&nbsp;2012&nbsp;R2. That&rsquo;s Windows PowerShell 4.0 to 4.0. Actually, it&rsquo;s Window Management Framework&nbsp;4.0 on both sides. WMF includes Windows PowerShell and the WSMAN stack. You can create remote connections between any of these versions of Windows PowerShell: 4.0, 3.0, or 2.0.\nThe important point to remember is that the functionality available through your remote session is controlled by the version of Windows PowerShell on the remote machine. You can&rsquo;t remote to a system running Windows PowerShell 2.0 and expect to use the new cmdlets in Windows PowerShell 4.0 that you have available on your local machine.\nAfter you have created a session, you can work with it interactively, or you can use <strong>Invoke-Command<\/strong> against the session. Entering a session enables you to work interactively on the remote session:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Enter-PSSession -Session $sess<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt; Get-CimInstance -ClassName Win32_OperatingSystem | Format-List<\/p>\n<p style=\"padding-left: 30px\">SystemDirectory : C:Windowssystem32<\/p>\n<p style=\"padding-left: 30px\">Organization&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">BuildNumber&nbsp;&nbsp;&nbsp;&nbsp; : 9600<\/p>\n<p style=\"padding-left: 30px\">RegisteredUser&nbsp; : Windows User<\/p>\n<p style=\"padding-left: 30px\">SerialNumber&nbsp;&nbsp;&nbsp; : 00252-00105-04511-AA037<\/p>\n<p style=\"padding-left: 30px\">Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6.3.9600<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt; Exit-PSSession<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt;\n<strong>Note<\/strong>&nbsp;&nbsp;I use &pound;&gt; as my prompt.\nThe session you created earlier is used with <strong>Enter-PSsession<\/strong>. It is possible to use the computer name instead of a pre-existing session:<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; Enter-PSSession -ComputerName win12r2<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt; Get-CimInstance -ClassName Win32_OperatingSystem | Format-List<\/p>\n<p style=\"padding-left: 30px\">SystemDirectory : C:Windowssystem32<\/p>\n<p style=\"padding-left: 30px\">Organization&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"padding-left: 30px\">BuildNumber&nbsp;&nbsp;&nbsp;&nbsp; : 9600<\/p>\n<p style=\"padding-left: 30px\">RegisteredUser&nbsp; : Windows User<\/p>\n<p style=\"padding-left: 30px\">SerialNumber&nbsp;&nbsp;&nbsp; : 00252-00105-04511-AA037<\/p>\n<p style=\"padding-left: 30px\">Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6.3.9600<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt; Exit-PSSession<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt;\nI&rsquo;m using the session because I want to reuse the connection later. In either case, when you are in the session, your prompt changes. In my case the local prompt is &pound;&gt;. The prompt of the session running in the remote session is:<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt;\nWhen you open a remote session, no profile scripts are run. What is interesting is the return from <strong>Get-PSSnapin<\/strong>. If you open a Windows PowerShell console in Windows&nbsp;8.1 or Windows&nbsp;8, and you run <strong>Get-PSSnapin<\/strong> (assuming your profile doesn&rsquo;t load anything), you&rsquo;ll get one response:<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Core\nIf you enter a session on a remote machine and repeat the call to <strong>Get-PSSnapin<\/strong>, you&rsquo;ll get a bit more back:<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Diagnostics<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Core<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Utility<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Host<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Management<\/p>\n<p style=\"padding-left: 30px\">Microsoft.PowerShell.Security<\/p>\n<p style=\"padding-left: 30px\">Microsoft.WSMan.Management\nThese are reported as snap-ins even though they are modules.\nThe module auto-load feature is still present, so you don&rsquo;t explicitly have to import modules. For example, you can use the <strong>NetConnection<\/strong> module:<\/p>\n<p style=\"padding-left: 30px\">[win12r2]: PS C:UsersRichardDocuments&gt; Get-NetConnectionProfile<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Manticore.org<\/p>\n<p style=\"padding-left: 30px\">InterfaceAlias&nbsp;&nbsp; : Virtual LAN<\/p>\n<p style=\"padding-left: 30px\">InterfaceIndex&nbsp;&nbsp; : 12<\/p>\n<p style=\"padding-left: 30px\">NetworkCategory&nbsp; : DomainAuthenticated<\/p>\n<p style=\"padding-left: 30px\">IPv4Connectivity : Internet<\/p>\n<p style=\"padding-left: 30px\">IPv6Connectivity : LocalNetwork<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Manticore.org<\/p>\n<p style=\"padding-left: 30px\">InterfaceAlias&nbsp; &nbsp;: Virtual Wireless<\/p>\n<p style=\"padding-left: 30px\">InterfaceIndex&nbsp;&nbsp; : 14<\/p>\n<p style=\"padding-left: 30px\">NetworkCategory&nbsp; : DomainAuthenticated<\/p>\n<p style=\"padding-left: 30px\">IPv4Connectivity : Internet<\/p>\n<p style=\"padding-left: 30px\">IPv6Connectivity : LocalNetwork\nAfter you have finished your interactive work and you can run scripts that exist on the remote machine, you can exit the session by using <strong>Exit-PSSession<\/strong>. If you used a session, it will still be available to use.\nYesterday, you saw how to use <strong>Invoke-Command<\/strong> to run a command against a remote machine:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -ComputerName server02 -ScriptBlock {Get-Service}\nYou can do exactly the same thing when you have a remote session available:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session $sess -ScriptBlock {get-service}\nOur session was created against a computer called Win12R2. Let&rsquo;s create another session against server02:<\/p>\n<p style=\"padding-left: 30px\">$sess2 = New-PSSession -ComputerName server02\nAnd then you can do this:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session $sess, $sess2 -ScriptBlock {get-service}\nEach object returned has the computer name appended in the <strong>PSComputerName<\/strong> as shown in this abbreviated output:<\/p>\n<p style=\"padding-left: 30px\">DisplayName&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;: Windows Driver Foundation &#8211; User-mode Driver Framework<\/p>\n<p style=\"padding-left: 30px\">Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Stopped<\/p>\n<p style=\"padding-left: 30px\">ServiceType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Win32ShareProcess<\/p>\n<p style=\"padding-left: 30px\">PSComputerName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : win12r2<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">DisplayName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Active Directory Web Services<\/p>\n<p style=\"padding-left: 30px\">Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Running<\/p>\n<p style=\"padding-left: 30px\">ServiceType &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Win32OwnProcess<\/p>\n<p style=\"padding-left: 30px\">PSComputerName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : server02\nYou can also create a session that spans multiple machines, but first remove the existing sessions:<\/p>\n<p style=\"padding-left: 30px\">Get-PSSession | Remove-PSSession<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $sessM = New-PSSession -ComputerName server02, win12r2<\/p>\n<p style=\"padding-left: 30px\">&pound;&gt; $sessM<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Id Name&nbsp;&nbsp;&nbsp; ComputerName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ConfigurationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Availability<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8212;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">&nbsp; 1 Session1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server02&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Opened&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.PowerShell&nbsp;&nbsp;&nbsp;&nbsp; Available<\/p>\n<p style=\"padding-left: 30px\">&nbsp; 2 Session2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; win12r2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Opened&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.PowerShell&nbsp;&nbsp;&nbsp;&nbsp; Available\nIf you use the session directly, you get results from all machines in the session:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session $sessM -ScriptBlock {get-service}\nAlternatively, you can access individual machines within a session:<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session (Get-PSSession -Name Session1) -ScriptBlock {get-service}<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command -Session (Get-PSSession -Name Session2) -ScriptBlock {get-service}\nCreating a remote session to connect to a server running Exchange Server is a little odd compared to what you&rsquo;ve seen so far. You can create a session exactly as described earlier, and you can run Windows PowerShell commands through it.\nWhat you can&rsquo;t do is import the Exchange PowerShell snap-in; that is (Microsoft.Exchange.Management.PowerShell.E2010 in Exchange Server&nbsp;2010 or Microsoft.Exchange.Management.PowerShell.SnapIn in Exchange Server&nbsp;2013). You will get an error message.\nWhen you install Exchange Server, it creates a specific remoting endpoint for you (endpoints will be covered in more detail later in the series). This is hosted in IIS rather than being a &ldquo;normal&rdquo; emoting endpoint. You have to connect like this:<\/p>\n<p style=\"padding-left: 30px\">$cred = Get-Credential<\/p>\n<p style=\"padding-left: 30px\">$sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri &#8220;http:\/\/MyExchangeServer\/PowerShell&#8221; -Authentication Kerberos -Credential $cred -ErrorAction Stop&nbsp; &nbsp;\nThe credentials that you use must be granted the required administrative permissions in Exchange. The connection URI is http:\/\/MyExchangeServer\/PowerShell, where you substitute your server name for MyExchangeServer.\nThis tells Windows PowerShell where to find its connection. If your DNS is functioning correctly, you can use only the server name. Otherwise, a FQDN is required.\nOut of interest, the Help file for <strong>New-PSSession<\/strong> states that the default ConnectionURI is http:\/\/localhost:5985\/WSMAN, which means for quick tests you can do this:<\/p>\n<p style=\"padding-left: 30px\">$sess = New-PSSession\nA session is opened on the local machine assuming you have remoting enabled.\nThe other parameter that you need for a connection to an Exchange server is <strong>ConfigurationName<\/strong>. This is the name in use by the session. Compare the session details for an Exchange Server connection with those for a standard Windows PowerShell connection shown earlier:<\/p>\n<p style=\"padding-left: 30px\">State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Opened<\/p>\n<p style=\"padding-left: 30px\">IdleTimeout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : -1<\/p>\n<p style=\"padding-left: 30px\">OutputBufferingMode&nbsp;&nbsp;&nbsp; : None<\/p>\n<p style=\"padding-left: 30px\">ComputerName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : MyExchangeServer<\/p>\n<p style=\"padding-left: 30px\">ConfigurationName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.Exchange<\/p>\n<p style=\"padding-left: 30px\">InstanceId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : ce246497-af2b-4087-8a17-6edd1031b579<\/p>\n<p style=\"padding-left: 30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Session1<\/p>\n<p style=\"padding-left: 30px\">Availability&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Available<\/p>\n<p style=\"padding-left: 30px\">ApplicationPrivateData : {SupportedVersions, ImplicitRemoting, PSVersionTable}<\/p>\n<p style=\"padding-left: 30px\">Runspace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : System.Management.Automation.RemoteRunspace\nNow you&rsquo;ve got your remote session to Exchange Server. What are you going to do with it?\nThe Exchange cmdlets are available, and if you try to use them in the same way as the remoting sessions you&rsquo;ve seen so far, your commands will appear to fail at odd moments. This isn&rsquo;t a problem. What&rsquo;s happening is that you have a constrained endpoint. This will be covered in more detail later; but for now, it means that you can&rsquo;t use variables, and some Windows PowerShell language features aren&rsquo;t available.\nThis is where you get to see what is probably one of the coolest remoting features. You can take your remote session and import it into your local machine. This is performed like this:<\/p>\n<p style=\"padding-left: 30px\">Import-PSSession $sess\nIf you don&rsquo;t want to see all of the messages, you can make the import quiet by using <strong>Out-Null<\/strong>:<\/p>\n<p style=\"padding-left: 30px\">Import-PSSession $sess | Out-Null\nAs an aside, this is a good method of suppressing output from any cmdlet that you don&rsquo;t want to see.\nThe result of the import is a module with a random name, such as tmp_qyllw5kj.gz1. As long as you have the session open, your module is available, and it is removed when you close the session. If you examine the contents of the module, you&rsquo;ll find that it contains proxy functions for the cmdlets that are available in the remote session. By using the module on your local machine, it works automatically across the remoting session. You have the full benefit of Windows PowerShell and access to the Exchange cmdlets.\nIf required, you can restrict the commands that are imported by using the <strong>CommandName<\/strong> parameter of <strong>Import-PSSSession<\/strong>. <strong>Import-PSSession<\/strong> also adds an <strong>&ndash;AsJob<\/strong> parameter to all of the proxy functions it creates to give you more flexibility for long running commands.\nIf you want a permanent module that contains the proxy functions for the Exchange cmdlets, use <strong>Export-PSSession<\/strong>, which will enable you to set the name of the module and save it to disk on your local machine for future use. Whether you do that or create a new temporary module each time is a preference dictated by your working patterns.\nYou have seen how to work with remote sessions and how you can import Windows PowerShell functionality from remote machines onto your local machine. Next time, you&rsquo;ll learn more about configuring remoting endpoints plus one of the issues that many people trip over: running commands on the remote machine against a third machine.\nBye for now.\n~Richard\nThanks, Richard. I look forward to reading the rest of this 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><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Richard Siddaway explains how to use WindowsPowerShell remoting sessions. &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. But how do I work with remote machines? &mdash;AP &nbsp;Hello AP, Honorary Scripting Guy, Richard Siddaway, here today filling [&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-2510","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 WindowsPowerShell remoting sessions. &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. But how do I work with remote machines? &mdash;AP &nbsp;Hello AP, Honorary Scripting Guy, Richard Siddaway, here today filling [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2510","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=2510"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2510\/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=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}