{"id":3251,"date":"2009-12-29T14:50:37","date_gmt":"2009-12-29T14:50:37","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/12\/29\/bringing-remote-commands-to-your-local-session\/"},"modified":"2019-02-18T13:06:03","modified_gmt":"2019-02-18T20:06:03","slug":"bringing-remote-commands-to-your-local-session","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/bringing-remote-commands-to-your-local-session\/","title":{"rendered":"Bringing remote commands to your local session"},"content":{"rendered":"<p>How can you manage multiple technologies installed on <u>separate machines<\/u> that expose their management surface through cmdlets?&#160; One approach would be to open remote desktop connection to each of those machines, another approach would be to send commands using Invoke-Command and PowerShell Remoting.&#160; But remote desktop is not a feasible solution for automation and invoking remote commands using Invoke-Command cmdlet can sometimes get burdensome &#8211; tab completion is missing, verbose incantations are needed for passing <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2009\/12\/29\/arguments-for-remote-commands.aspx\">arguments to remote commands<\/a> and Get-Help -Online doesn&#8217;t quite work in a remote session. <\/p>\n<p>That\u2019s where <strong>IMPLICIT REMOTING<\/strong> comes to play \u2013 ability to import remote commands into your local session. One can even store the information about imported commands on disk for later use, details in a <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2009\/12\/29\/saving-remote-session-to-your-local-disk.aspx\">later post<\/a>. Implicit remoting is a feature that smoothes out the user experience of invoking remote commands.<\/p>\n<h3>Importing remote commands into local session<\/h3>\n<p>Let&#8217;s see how one can import a remote command into a local session. First \u2013 let\u2019s ask Import-PSSession cmdlet to look in the remote session $s, take all the remote commands matching &quot;*-Process&quot; wildcard, add a &quot;Remote&quot; prefix to their noun, and then present them to me as if they were local commands: <\/p>\n<pre>PS&gt; $s = <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=135237\">New-PSSession<\/a> -ComputerName lukasza5 -Credential REDMOND\\lukasza\nPS&gt; <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=135221\">Import-PSSession<\/a> -Session $s -CommandName *-Process -Prefix Remote\nModuleType Name                      ExportedCommands\n---------- ----                      ----------------\nScript     tmp_a50e3c88-46f1-4c25... {Stop-Process, Get-Process, Debug-Process, Wait-Process...}<\/pre>\n<h3>Implicit remoting experience<\/h3>\n<p>The basic promise behind implicit remoting is that you can work with remote commands using local syntax. In particular &#8211; after Import-PSSession did its magic I can invoke remote commands as if they were local commands. Let&#8217;s see if Get-RemoteProcess really works on a different machine than Get-Process: <\/p>\n<pre>PS&gt; Get-RemoteProcess -Name w*host\nHandles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName\n-------  ------    -----      ----- -----   ------     -- -----------\n    313      10    39000      51044   162     2.18   2348 wsmprovhost\nPS&gt; Get-Process -Name w*host\nHandles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName\n-------  ------    -----      ----- -----   ------     -- -----------\n    216      11     2056       6132    61     0.09   1208 WUDFHost<\/pre>\n<p>Below is a list of other things that you can try: <\/p>\n<ul>\n<li>Get-RemotePr&lt;tab&gt;: tab completion on remote command and parameter names <\/li>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113316\">Get-Help<\/a> Get-RemoteProcess: downloading help content from remote session and displaying it on a local box <\/li>\n<li>Get-RemoteProcess -Name $localVariable: binding local variables as <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2009\/12\/29\/arguments-for-remote-commands.aspx\">arguments to parameters of remote commands<\/a> <\/li>\n<li>Get-RemoteProcess -AsJob: invoking remote commands as background jobs using an extra switch parameter added to remote commands <\/li>\n<li>Get-RemoteProcess -OutVariable global:localVariable | Out-Null: storing results of remote invocation in a local variable (scope prefix is unfortunately necessary because of implementation details) <\/li>\n<li>Get-RemoteProcess | Select-Object -Last 5: mixing remote and local commands in a single pipeline <\/li>\n<\/ul>\n<p>Thanks,<\/p>\n<p>Lukasz Anforowicz [MSFT]\n  <br \/>Windows PowerShell Developer\n  <br \/>Microsoft Corporation<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can you manage multiple technologies installed on separate machines that expose their management surface through cmdlets?&#160; One approach would be to open remote desktop connection to each of those machines, another approach would be to send commands using Invoke-Command and PowerShell Remoting.&#160; But remote desktop is not a feasible solution for automation and invoking [&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":[8],"class_list":["post-3251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-remoting"],"acf":[],"blog_post_summary":"<p>How can you manage multiple technologies installed on separate machines that expose their management surface through cmdlets?&#160; One approach would be to open remote desktop connection to each of those machines, another approach would be to send commands using Invoke-Command and PowerShell Remoting.&#160; But remote desktop is not a feasible solution for automation and invoking [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3251","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=3251"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/3251\/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=3251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=3251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=3251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}