<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://code.msdn.microsoft.com/rss.xsl"?><rss version="2.0"><channel><title>PowerShellTunnel - script your app from PowerShell at runtime</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Project/ProjectRss.aspx</link><description>Use an ordinary PowerShell console to access your application&amp;#39;s objects &amp;#40;explicitly hosted in a PowerShell runspace&amp;#41; at runtime, including tab expansion and piping objects into and out of your appl...</description><item><title>UPDATED WIKI: PowerShellTunnel Considerations</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Considerations&amp;version=15</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Considerations
&lt;/h1&gt; &lt;br /&gt;&lt;b&gt;A)&lt;/b&gt; If you don't want to connect to an existing embedded runspace but instead want to remote-connect to new PowerShell 'consoles' on remote clients, refer instead to PowerShell 2.0 or the &amp;quot;PowerShell Remoting&amp;quot; project.  PowerShellTunnel is designed for connecting to an existing console or runspace.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;B)&lt;/b&gt; The &lt;a href="http://thepowershellguy.com/blogs/posh/pages/powertab.aspx" class="externalLink"&gt;PowerTab&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; project could make tab expansion integration cleaner.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;C)&lt;/b&gt; Serialization: PowerShellTunnel uses ordinary serialization by serialized pipied input or output objects to a stream and sending a raw byte array to and from the tunnel host.  If the class is not serializable then just the type name will be sent.  PowerShellTunnel does not use WCF data contract serialization for the piped objects themselves.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;D)&lt;/b&gt; TODO: Add 'help', 'verbose', functionality to cmdlets.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;E)&lt;/b&gt; Security Warning: once connected to the tunnel host, the tunnel has access to all of the tunnel host's exposed objects and functionality (c.f. &lt;a href="http://www.codeplex.com/Skynet" class="externalLink"&gt;Skynet&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;).  (Future Powershell runspaces may be restrictable to limit what objects can be accessed.)&lt;br /&gt; &lt;br /&gt;&lt;b&gt;F)&lt;/b&gt; Multiple hosts/clients: You can create multiple tunnel hosts and multiple tunnels, e.g. a host may be accessed by multiple clients.  A client may use multiple tunnels (to different hosts) and use: &amp;quot;select-tunnel&amp;quot; to switch between them or use the &amp;quot;-tunnel&amp;quot; parameter of &amp;quot;invoke-tunnel&amp;quot;.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;G)&lt;/b&gt; Threading: Be aware of threading considerations given that the tunnel host executes on a WCF worker thread (e.g. on a .NET Thread Pool thread).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;H)&lt;/b&gt; No Ctrl-C?  If you invoke-tunnel a script, Ctrl-C from the client does not interrupt it, so beware of infinite loops or long operations.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;I)&lt;/b&gt; After 'select-tunnel' (or add-tunnel without the -noselect switch), tab expansion is intercepted to to tab expansion on the tunnel host.  This is useful when typing the script block of the invoke-tunnel but not especially elsewhere.  Use select-tunnel without a parameter to turn off the tab expansion interception (and requires invoke-tunnel to specify a '-tunnel xyz' parameter).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;J)&lt;/b&gt; There might be ways to streamline the user syntax/experience further.  In the meanwhile, consider using an alias to Invoke-Tunnel, e.g.&lt;br /&gt;&lt;span class="codeInline"&gt;Set-Alias T Invoke-Tunnel&lt;/span&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;Set-Alias TP Invoke-Tunnel -pipeoutput&lt;/span&gt;&lt;br /&gt;or&lt;br /&gt;&lt;span class="codeInline"&gt;function T1 { Invoke-Tunnel -tunnel $mytunnel1 $args} &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Thu, 03 Apr 2008 04:56:27 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Considerations 20080403A</guid></item><item><title>CREATED ISSUE: Increase WCF Default Message Size Limits</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/WorkItem/View.aspx?WorkItemId=1</link><description>The default WCF mssage receive size limit of 65536 bytes can be easily hit.  Increase this to 1000000000 bytes by default.  Also increase WCF data contract serializer setting MaxItemsInObjectGraph and set PreserveReferences to true.&lt;br /&gt;</description><author>MatHobbs</author><pubDate>Wed, 19 Mar 2008 03:16:40 GMT</pubDate><guid isPermaLink="false">CREATED ISSUE: Increase WCF Default Message Size Limits 20080319A</guid></item><item><title>NEW POST: Using invoke-tunnel on XP SP2</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Thread/View.aspx?ThreadId=173</link><description>&lt;div class="wikidoc"&gt;
Hi Marco, ah yes: WCF's default limits.  Your $x probably referenced an object that would be serialized to &amp;gt; 65536 bytes.  I uploaded a new PowerShellTunnel release (&amp;quot;1.01&amp;quot;) that bumps up two important WCF settings so you should not get this any more unless your objects is &amp;gt; 1000000000 bytes!&lt;br /&gt; &lt;br /&gt;Cheers,&lt;br /&gt;-Mat&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Wed, 19 Mar 2008 03:13:47 GMT</pubDate><guid isPermaLink="false">NEW POST: Using invoke-tunnel on XP SP2 20080319A</guid></item><item><title>CREATED RELEASE: PowerShellTunnel v1.01 Source (Mar 18, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=686</link><description>Additions only for the default WCF behavior&amp;#58;&lt;br /&gt;1&amp;#41; Increase the default MaxReceivedMessageSize so large objects can be serialized and piped without a WCF error.&lt;br /&gt;2&amp;#41; Add a custom data contract serializer behavior to increase MaxItemsInObjectGraph too.</description><author></author><pubDate>Wed, 19 Mar 2008 03:09:02 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: PowerShellTunnel v1.01 Source (Mar 18, 2008) 20080319A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Quick Start</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Quick Start&amp;version=45</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Quick Start
&lt;/h1&gt; &lt;br /&gt;With PowerShellTunnel you create a tunnel between two endpoints: the tunnel 'host' and the tunnel 'client' - you need to start both.  You send scripts from the client to execute on the host as if you had typed them directly into the host (including tab expansion), so you have access to all the objects and capabilities of the host from the client.  Objects can be piped into or out of the tunnel (ordinary serialization is used).&lt;br /&gt; &lt;br /&gt;If you want to follow through the quick start, you'll need to first go through &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Build&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;This quick-start works through two scenarios:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Console -&amp;gt; Console&lt;/b&gt;:  Two PowerShell consoles, one acts as a tunnel host, the other as a tunnel client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Console -&amp;gt; Application&lt;/b&gt;:  One ordinary .NET console application with an embedded PowerShell runspace (which exposes some application objects as ordinary PowerShell variables) which hosts a tunnel, and an ordinary PowerShell console which acts as a tunnel client to interact with the application's objects while the application is running.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h1&gt;
Console -&amp;gt; Console
&lt;/h1&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell console with a couple of objects which we will try to access from another PowerShell console (the tunnel client).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;1-a)	Start a PowerShell console.&lt;br /&gt;	&lt;br /&gt;1-b)	Enter the following commands to add the snapin, add a tunnel host (use the address you specified when you did the install, or refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt; to add an http permission for your user if necessary), and create a couple of ordinary objects:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnelhost = add-tunnelhost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
$x = dir
$y = $x[0]
&lt;/pre&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin and add a tunnel to the tunnel host (using the same address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N{TAB} becomes $y.Name.  The pipeline should work (both in and out) so long as types are WCF-OK (standard types or types made known to WCF &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=...&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;...&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } }
$myx = invoke-tunnel { $x } -pipe    #sets $myx to a list of DirectoryInfo and FileInfo objects piped from the host
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt;Note: if there are multiple tunnels, then select-tunnel can be used to change the current invoke-tunnel default (and redirect tab expansion), or invoke-tunnel can be called with a '-tunnel xyz' parameter.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 3) Switch back to the host console and verify that you see:
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
write line #1
write line #2
write line #3
&lt;/pre&gt;and verify that $z was created:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$z  #You'll see &amp;quot;This variable is set on the host!&amp;quot;
&lt;/pre&gt;&lt;h3&gt;
Step 4) Switch back to the client console and remove (close) the Tunnel and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-Tunnel $tunnel
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h3&gt;
Step 5) Switch back to the host console and remove (close) the Tunnel Host and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-TunnelHost $tunnelhost
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h2&gt;
Console -&amp;gt; Application
&lt;/h2&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell runspace hosted (embedded) within a console application (PowerShellTunnel.Embeddable.Example.exe) which 'exposes' a few of its objects as PowerShell variables in the hosted runspace.  The client will be an ordinary PowerShell console as before.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;First, if you are re-using the same host address from before, close the tunnel host console from the 'Console -&amp;gt; Console' walkthrough if it is still open.&lt;br /&gt; &lt;br /&gt;Build and run PowerShellTunnel.Embeddable.Example.exe.  This is a console application that outputs some information and waits on a Console.Readline() where pressing Enter exits the application.   A PowerShell runspace is hosted and a tunnel host created in the runspace at address &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot; (or change this value in program.cs).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;	2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N&amp;lt;TAB&amp;gt; becomes $y.Name. The pipeline should work (both in and out) so long as the piped types are serializable.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 }
&lt;/pre&gt;The same kinds of access is available as before with some warnings:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;ol&gt;
&lt;li&gt;The example hosted runspace does not have a console so any scripts which access the console in any way will fail (you can create a more advanced host).&lt;/li&gt;&lt;li&gt;The tunnel host gets its requests on WCF worker threads, so be aware of multi-threading issues on whatever is exposed via the runspace.&lt;/li&gt;&lt;li&gt;Be aware that the client has access to anything that the hosted runspace has.&lt;/li&gt;&lt;li&gt;You may want to configure WCF security in the general case.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
General Notes
&lt;/h2&gt; &lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel Considerations&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Wed, 19 Mar 2008 03:00:05 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Quick Start 20080319A</guid></item><item><title>EDITED ISSUE: Increase WCF Default Message Size Limits</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/WorkItem/View.aspx?WorkItemId=1</link><description>The default WCF mssage receive size limit of 65536 bytes can be easily hit.  Increase this to 1000000000 bytes by default.  Also increase WCF data contract serializer setting MaxItemsInObjectGraph and set PreserveReferences to true.&lt;br /&gt;</description><author>MatHobbs</author><pubDate>Wed, 19 Mar 2008 00:17:32 GMT</pubDate><guid isPermaLink="false">EDITED ISSUE: Increase WCF Default Message Size Limits 20080319A</guid></item><item><title>NEW POST: Using invoke-tunnel on XP SP2</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Thread/View.aspx?ThreadId=173</link><description>&lt;div class="wikidoc"&gt;
Following your guides:&lt;br /&gt; &lt;br /&gt;PSH&amp;gt; invoke-tunnel { $x }&lt;br /&gt;Invoke-Tunnel : The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota,&lt;br /&gt;use the MaxReceivedMessageSize property on the appropriate binding element.&lt;br /&gt;At line:1 char:14&lt;br /&gt;+ invoke-tunnel &amp;lt;&amp;lt;&amp;lt;&amp;lt;  { $x }&lt;br /&gt; &lt;br /&gt;Still appears things are working.&lt;br /&gt;
&lt;/div&gt;</description><author>marcoshaw</author><pubDate>Fri, 14 Mar 2008 17:28:56 GMT</pubDate><guid isPermaLink="false">NEW POST: Using invoke-tunnel on XP SP2 20080314P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=Home&amp;version=27</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel
&lt;/h1&gt; &lt;br /&gt;Host a PowerShell runspace and expose application objects as ordinary PowerShell variables.  Add a &amp;#39;tunnel host&amp;#39;, then use an ordinary &amp;#40;local or remote&amp;#41; PowerShell console &amp;#40;or runspace&amp;#41; to &amp;#39;tunnel&amp;#39; &amp;#40;connect using WCF&amp;#41; to your application&amp;#39;s runspace at runtime and script away.
&lt;br /&gt;&lt;h3&gt;
Contents
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=Home&amp;amp;referringTitle=Home"&gt;Home&lt;/a&gt; - where you are now.&lt;/li&gt;&lt;li&gt;&lt;b&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Quick%20Start&amp;amp;referringTitle=Home"&gt;PowerShellTunnel Quick Start&lt;/a&gt;&lt;/b&gt; - a quick step-by-step walk-through of PowerShellTunnel.&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=Home"&gt;PowerShellTunnel How to Install&lt;/a&gt; - a guide to requirements and installing PowerShellTunnel.&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Uninstall&amp;amp;referringTitle=Home"&gt;PowerShellTunnel How to Uninstall&lt;/a&gt; - a guide to uninstalling PowerShellTunnel.&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=Home"&gt;PowerShellTunnel How to Build&lt;/a&gt; - a guide to building PowerShellTunnel.&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Reference&amp;amp;referringTitle=Home"&gt;PowerShellTunnel Reference&lt;/a&gt; - a guide to the cmdlets and &lt;span class="codeInline"&gt;PowerShellTunnel.sln&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=Home"&gt;PowerShellTunnel Considerations&lt;/a&gt; - notes on various issues relating to PowerShellTunnel.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;
PowerShellTunnel, what is it and why is it..
&lt;/h3&gt; &lt;br /&gt;While using &lt;a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" class="externalLink"&gt;PowerShell&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to construct and manipulate .NET objects, did you ever think that it would be pretty cool to be able to open a PowerShell console and connect to and directly access the objects of a running application (at least the objects it exposes)?  (You can't do this with Remoting in PowerShell 2.0 where you can only open new remote consoles.)&lt;br /&gt; &lt;br /&gt;For example you might want to do:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Ad-hoc debugging, diagnostics, or monitoring.&lt;/li&gt;&lt;li&gt;Change object properties or calling methods at runtime.&lt;/li&gt;&lt;li&gt;Ad-hoc (or scripted) unit, system, or integrity tests on a live application.&lt;/li&gt;&lt;li&gt;Simulate events and actions.&lt;/li&gt;&lt;li&gt;Allow automation of your application without explicit interface contracts (ad-hoc or prototyping APIs).&lt;/li&gt;&lt;li&gt;Perhaps even adding or changing functionality on-the-fly.&lt;/li&gt;&lt;li&gt;... probably many other things you might think of.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;There is an existing &lt;a href="http://www.codeplex.com/powershellremoting" class="externalLink"&gt;PowerShell Remoting&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; project which uses a remote service to which you connect to to create a PowerShell host that you talk to through your client connection.  This isn't quite what what I was after and after hearing that &lt;a href="http://blogs.msdn.com/powershell/archive/2007/11/06/what-s-new-in-ctp-of-powershell-2-0.aspx" class="externalLink"&gt;PowerShell 2.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; was coming, decided to wait and see.  So PowerShell 2.0 CTP is here and does have Remoting ability but this is also focused on the administrative desire to summon a PowerShell console on a remote host and control it from the client, but neither approach can connect to an existing application's embedded PowerShell runspace.&lt;br /&gt; &lt;br /&gt;So, after some reading and playing, PowerShellTunnel was created.  PowerShellTunnel is a single VS2005 solution containing:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Server-side cmdlets allowing you to start a 'tunnel host' from a PowerShell console or runspace.  A 'tunnel host' allows 'tunnels' (tunnel clients) to access your console/runspace.&lt;/li&gt;&lt;li&gt;Client-side cmdlets allowing you to start a 'tunnel' (connection) from a PowerShell console or runspace to an existing tunnel host (local or remote) and send scripts to onvoke on the tunnel host console/runspace.  This includes piping objects in and out.&lt;/li&gt;&lt;li&gt;Tab-expansion 'works' on the client: pressing tab will return tab expansion results from the tunnel host's runspace.  A gotcha (for now) is that as long as you have a 'current tunnel' selected, tab expansion always diverts to the current tunnel's host.&lt;/li&gt;&lt;li&gt;An ordinary 'embeddable' PowerShell runspace class (hostable by any .NET app) where you explicitly specify what objects to expose (specifying which PowerShell variable names) and any tunnel hosts to host.&lt;/li&gt;&lt;li&gt;An example of a console application with a few simple objects that you can use to connect to from an ordinary PowerShell console.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;Note that:&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;WCF is used to do all the legwork of the underlying connection, by default the code uses http.  By using WCF we avoid having to code for transport options, security, and other issues as this should be all achievable through WCF.&lt;/li&gt;&lt;li&gt;Serializable objects can be piped into and out of the tunnel.&lt;/li&gt;&lt;li&gt;The cmdlets also allow an ordinary PowerShell console to act as a tunnel host.  This is the easiest way to start playing with PowerShellTunnel: use one PowerShell console as the tunnel host and another as the tunnel client.  Similarly an embedded runspace could start a tunnel to any tunnel host too.&lt;/li&gt;&lt;li&gt;Any console or runspace can have multiple tunnel hosts and/or can have multiple tunnels open.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;To make a long story short, review the &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Quick%20Start&amp;amp;referringTitle=Home"&gt;PowerShellTunnel Quick Start&lt;/a&gt; to see if this suits you.  Use the Issue Tracker for any bugs or suggestions.&lt;br /&gt;Use the Discussions tab for questions, comments, ideas, or to share how you have used PowerShellTunnel.&lt;br /&gt; &lt;br /&gt;Cheers,&lt;br /&gt;-Matthew Hobbs&lt;br /&gt;&lt;a href="http://objectbusiness.wordpress.com" class="externalLink"&gt;(Very) Intermittent Blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Thu, 13 Mar 2008 02:34:31 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080313A</guid></item><item><title>UPDATED RELEASE: PowerShellTunnel v1.0 Source (Mar 02, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=595</link><description>First release &amp;#40;source only&amp;#41; including the source required to build the PowerShellTunnel assembly &amp;#40;PowerShellTunnel.dll&amp;#41; and an example application host &amp;#40;PowerShellTunnel.Embeddable.Example.exe&amp;#41;.</description><author></author><pubDate>Mon, 03 Mar 2008 04:34:18 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: PowerShellTunnel v1.0 Source (Mar 02, 2008) 20080303A</guid></item><item><title>RELEASED: PowerShellTunnel v1.0 Source (Mar 02, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=595</link><description>First release &amp;#40;source only&amp;#41; including the source required to build the PowerShellTunnel assembly &amp;#40;PowerShellTunnel.dll&amp;#41; and an example application host &amp;#40;PowerShellTunnel.Embeddable.Example.exe&amp;#41;.</description><author></author><pubDate>Mon, 03 Mar 2008 04:34:18 GMT</pubDate><guid isPermaLink="false">RELEASED: PowerShellTunnel v1.0 Source (Mar 02, 2008) 20080303A</guid></item><item><title>UPDATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=595</link><description>Initial source-only release including the source required to build the PowerShellTunnel assembly &amp;#40;PowerShellTunnel.dll&amp;#41; and an example application host &amp;#40;PowerShellTunnel.Embeddable.Example.exe&amp;#41;.</description><author></author><pubDate>Mon, 03 Mar 2008 04:32:41 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008) 20080303A</guid></item><item><title>UPDATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=595</link><description>Initial source-only release including the PowerShellTunnel assembly &amp;#40;PowerShellTunnel.dll&amp;#41; and an example application host &amp;#40;PowerShellTunnel.Embeddable.Example.exe&amp;#41;.</description><author></author><pubDate>Mon, 03 Mar 2008 04:31:24 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008) 20080303A</guid></item><item><title>CREATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008)</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Release/ProjectReleases.aspx?ReleaseId=595</link><description>Initial source-only release including the PowerShellTunnel assembly &amp;#40;PowerShellTunnel.dll&amp;#41; and an example application host &amp;#40;PowerShellTunnel.Embeddable.Example.exe&amp;#41;.</description><author></author><pubDate>Mon, 03 Mar 2008 04:29:10 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: PowerShellTunnel - Initial Release (Source) (Mar 02, 2008) 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Considerations</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Considerations&amp;version=14</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Considerations
&lt;/h1&gt; &lt;br /&gt;&lt;b&gt;A)&lt;/b&gt; If you don't want to connect to an existing embedded runspace but instead want to remote-connect to new PowerShell 'consoles' on remote clients, refer instead to PowerShell 2.0 or the &amp;quot;PowerShell Remoting&amp;quot; project.  PowerShellTunnel is designed for connecting to an existing console or runspace.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;B)&lt;/b&gt; The &lt;a href="http://thepowershellguy.com/blogs/posh/pages/powertab.aspx" class="externalLink"&gt;PowerTab&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; project could make tab expansion integration cleaner.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;C)&lt;/b&gt; Serialization: PowerShellTunnel uses ordinary serialization by serialized pipied input or output objects to a stream and sending a raw byte array to and from the tunnel host.  If the class is not serializable then just the type name will be sent.  PowerShellTunnel does not use WCF data contract serialization for the piped objects themselves.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;D)&lt;/b&gt; TODO: Add 'help', 'verbose', functionality to cmdlets.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;E)&lt;/b&gt; Security Warning: once connected to the tunnel host, the tunnel has access to all of the tunnel hosts exposed objects and functionality.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;F)&lt;/b&gt; Multiple hosts/clients: You can create multiple tunnel hosts and multiple tunnels, e.g. a host may be accessed by multiple clients.  A client may use multiple tunnels (to different hosts) and use: &amp;quot;select-tunnel&amp;quot; to switch between them or use the &amp;quot;-tunnel&amp;quot; parameter of &amp;quot;invoke-tunnel&amp;quot;.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;G)&lt;/b&gt; Threading: Be aware of threading considerations given that the tunnel host executes on a WCF worker thread (e.g. on a .NET Thread Pool thread).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;H)&lt;/b&gt; No Ctrl-C?  If you invoke-tunnel a script, Ctrl-C from the client does not interrupt it, so beware of infinite loops or long operations.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;I)&lt;/b&gt; After 'select-tunnel' (or add-tunnel without the -noselect switch), tab expansion is intercepted to to tab expansion on the tunnel host.  This is useful when typing the script block of the invoke-tunnel but not especially elsewhere.  Use select-tunnel without a parameter to turn off the tab expansion interception (and requires invoke-tunnel to specify a '-tunnel xyz' parameter).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;J)&lt;/b&gt; There might be ways to streamline the user syntax/experience further.  In the meanwhile, consider using an alias to Invoke-Tunnel, e.g.&lt;br /&gt;&lt;span class="codeInline"&gt;Set-Alias T Invoke-Tunnel&lt;/span&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;Set-Alias TP Invoke-Tunnel -pipeoutput&lt;/span&gt;&lt;br /&gt;or&lt;br /&gt;&lt;span class="codeInline"&gt;function T1 { Invoke-Tunnel -tunnel $mytunnel1 $args} &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 04:13:25 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Considerations 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Considerations</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Considerations&amp;version=13</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Considerations
&lt;/h1&gt; &lt;br /&gt;&lt;b&gt;A)&lt;/b&gt; If you don't want to connect to an existing embedded runspace but instead want to remote-connect to new PowerShell 'consoles' on remote clients, refer instead to PowerShell 2.0 or the &amp;quot;PowerShell Remoting&amp;quot; project.  PowerShellTunnel is designed for connecting to an existing console or runspace.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;B)&lt;/b&gt; The &lt;a href="http://thepowershellguy.com/blogs/posh/pages/powertab.aspx" class="externalLink"&gt;PowerTab&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; project could make tab expansion integration cleaner.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;C)&lt;/b&gt; Serialization: PowerShellTunnel uses ordinary serialization by serialized pipied input or output objects to a stream and sending a raw byte array to and from the tunnel host.  If the class is not serializable then just the type name will be sent.  PowerShellTunnel does not use WCF data contract serialization for the piped objects themselves.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;D)&lt;/b&gt; TODO: Add 'help', 'verbose', functionality to cmdlets.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;E)&lt;/b&gt; Security Warning: once connected to the tunnel host, the tunnel has access to all of the tunnel hosts exposed objects and functionality.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;F)&lt;/b&gt; Multiple hosts/clients: You can create multiple tunnel hosts and multiple tunnels, e.g. a host may be accessed by multiple clients.  A client may use multiple tunnels (to different hosts) and use: &amp;quot;select-tunnel&amp;quot; to switch between them or use the &amp;quot;-tunnel&amp;quot; parameter of &amp;quot;invoke-tunnel&amp;quot;.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;G)&lt;/b&gt; Threading: Be aware of threading considerations given that the tunnel host executes on a WCF worker thread (e.g. on a .NET Thread Pool thread).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;H)&lt;/b&gt; No Ctrl-C?  If you invoke-tunnel a script, Ctrl-C from the client does not interrupt it, so beware of infinite loops or long operations.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;I)&lt;/b&gt; After 'select-tunnel' (or add-tunnel without the -noselect switch), tab expansion is intercepted to to tab expansion on the tunnel host.  This is useful when typing the script block of the invoke-tunnel but not especially elsewhere.  Use select-tunnel without a parameter to turn off the tab expansion interception (and requires invoke-tunnel to specify a '-tunnel xyz' parameter).&lt;br /&gt; &lt;br /&gt;&lt;b&gt;J)&lt;/b&gt; There might be ways to streamline the user syntax/experience further.  In the meanwhile, consider using an alias to Invoke-Tunnel, e.g.&lt;br /&gt;&lt;span class="codeInline"&gt;Set-Alias T Invoke-Tunnel&lt;/span&gt;&lt;br /&gt;or&lt;br /&gt;&lt;span class="codeInline"&gt;function T1 { Invoke-Tunnel -tunnel $mytunnel1 $args} &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 04:10:50 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Considerations 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Reference</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Reference&amp;version=29</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel Reference
&lt;/h1&gt; &lt;br /&gt;There is a single Visual Studio 2005 solution (PowerShellTunnel.sln) containing two projects.&lt;br /&gt; &lt;br /&gt;The first project is the main PowerShellTunnel.dll project which consists of: a) the server (tunnel host) PowerShell cmdlets (Host folder); b) the client (tunnel) PowerShell cmdlets (Client folder); and c) an example embedded PowerShell runspace class for use within a .NET application (Embeddable folder).&lt;br /&gt; &lt;br /&gt;The second project (PowerShellTunnel.Embeddable.Example.exe) is an example of a .NET application (a console app) hosting an embedded runspace which you can communicate to from an ordinary PowerShell console window (using a tunnel).&lt;br /&gt; &lt;br /&gt;Note that there are assembly references to System.Management.Automation.dll which is a PowerShell SDK assembly - ref the Vista SDK.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Glossary
&lt;/h2&gt; &lt;br /&gt;&lt;b&gt;PowerShell console or runspace&lt;/b&gt; - a PowerShell console is an ordinary PowerShell shell windos, a PowerShell runspace is a non-visual PowerShell 'console'.  (A PowerShell console contains a PowerShell runspace.)&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Tunnel Host&lt;/b&gt; - a (WCF) service host listening for requests to run a script (allowing objects to be piped in) and returning any piped output objects.  A Tunnel Host is instantiated by a PowerShell console or runspace against which any arriving scripts are invoked.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Tunnel&lt;/b&gt; - a (WCF implemented) connection to a Tunnel Host (local or remote) through which scripts can be sent (along with any objects to be piped in) and receiving any response (incliuding any output piped objects).&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
PowerShellTunnel Assembly
&lt;/h2&gt; &lt;br /&gt;PowerShellTunnel.dll contains the host and client PowerShell cmdlets and an example embedded PowerShell runspace class.&lt;br /&gt;Before using any of the PowerShell cmdlets you need to:&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;First: install PowerShellTunnel (see &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Reference"&gt;PowerShellTunnel How to Install&lt;/a&gt;) - this is a one-off step.&lt;/li&gt;&lt;li&gt;Secondly: each time you open a console (or runspace) you need to add the snapin:&lt;/li&gt;
&lt;/ol&gt;=&lt;span class="codeInline"&gt;add-pssnapin PowerShellTunnel&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Tunnel Hosting Cmdlets
&lt;/h3&gt; &lt;br /&gt;Tunnel hosting cmdlets are run from a PowerShell console or runspace to add (instantiate) or remove a tunnel host.  Each tunnel host is tied to a WCF endpoint address from which it receives each incoming script request (on a .NET thread pool thread) and invokes the script on the PowerShell console or runspace and manages the serialization (using standard serialization to and from a byte array so the types must be known at each end) of objects piped into or out of the invocation.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Add-TunnelHost
&lt;/h4&gt; &lt;br /&gt;Only one parameter is input (which may be a pipeline input), the base address to listen on.&lt;br /&gt;A tunnel host (a WCF service host: System.ServiceModel.ServiceHost) instance is returned.&lt;br /&gt;In the current code only Http is used but any WCF-supported transport is possible.&lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Reference"&gt;PowerShellTunnel How to Install&lt;/a&gt; for help on any setup configuration you need to do.&lt;br /&gt;Any security or configurability we can defer entrely to WCF.&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;$tunnelhost = Add-TunnelHost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Remove-TunnelHost
&lt;/h4&gt; &lt;br /&gt;An added tunnel host should clean itself up when the PowerShell console or runspace's process is closed.  Remove-TunnelHost can be used to do this beforehand.&lt;br /&gt; &lt;br /&gt;Only one parameter is input (which may be a pipeline input), the tunnel host (WCF service host) to remove (close).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;Remove-TunnelHost $tunnelhost&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Tunnel cmdlets
&lt;/h3&gt; &lt;br /&gt;Tunnel cmdlets are run from a PowerShell console or runspace to make a connection to an already existing local or remote tunnel host (local or remote).  Each tunnel is a WCF connection to one tunnel host.  A script can be invoked on the tunnel (Invoke-Tunnel) whereby it is executed on the tunnel hosts' PowerShellconsole or runspace.  The tunnel handles serialization (using standard serialization to and from a byte array so types must be known at each end) of objects piped into or out of the script invocation (see &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Serialization&amp;amp;referringTitle=PowerShellTunnel%20Reference"&gt;PowerShellTunnel Serialization&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Add-Tunnel
&lt;/h4&gt; &lt;br /&gt;There are three parameters:&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;HostAddress&lt;/b&gt; (mandatory) - the address (e.g. &amp;quot;http://...&amp;quot;) of the tunnel host.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Binding&lt;/b&gt; - optional Binding object if not using the default WsHttpBinding.&lt;/li&gt;&lt;li&gt;&lt;b&gt;NoSelect&lt;/b&gt; - optional switch to prevent the new tunnel from automatically being selected as the default (i.e. bypass doing an automatic Select-Tunnel).&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;i&gt;Example&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;$tunnel = Add-Tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;A new tunnel instance is returned (if you only ever plan on using one tunnel in the session you don't need to retain this value).&lt;br /&gt; &lt;br /&gt;Unless &amp;quot;-NoSelect&amp;quot; is explicitly specified, the newly created tunnel will be 'selected' - see Select-Tunnel below.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Select-Tunnel
&lt;/h4&gt; &lt;br /&gt;&lt;i&gt;Example&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;Select-Tunnel $tunnel&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;If you use Add-Tunnel without specifying &amp;quot;-NoSelect&amp;quot; then the newly added tunnel be be automatically 'selected'.&lt;br /&gt; &lt;br /&gt;'Selecting' a tunnel has two effects:&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Redirect tab-expansion&lt;/b&gt; - pressing TAB will normally call function:tabexpansion, Select-Tunnel renames this and substitutes code to pass tab expansion onto the tunnel host instead.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Default tunnel for Invoke-Tunnel&lt;/b&gt; - when calling Invoke-Tunnel (see below) a tunnel does not need to be explicitly specified, instead the 'selected' tunnel is used.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;If switching between multiple tunnels you could use Select-Tunnel each time in order to redirect tab expansion each time.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Invoke-Tunnel
&lt;/h4&gt; &lt;br /&gt;Invokes a script on the tunnel host of the optionally specified tunnel.  If no tunnel is specified, the currently 'selected' tunnel (as specified by the last call to Select-Tunnel or Add-Tunnel without specifying the -NoSelect switch) is used.&lt;br /&gt; &lt;br /&gt;There are three parameters:&lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;ScriptBlock&lt;/b&gt; (mandatory) - the script to execute on the tunnel host's PowerShell console or runspace..&lt;/li&gt;&lt;li&gt;&lt;b&gt;Tunnel&lt;/b&gt; - optional tunnel instance on which to invoke the script (defaults to the current'y 'selected' tunnel).&lt;/li&gt;&lt;li&gt;&lt;b&gt;-PipeOutput&lt;/b&gt; (optional switch) - return serialized (if possible) output to the client.  If not provided (the default) then any output will be first formatted on the host (using &lt;span class="codeInline"&gt;Out-String -stream&lt;/span&gt;) and the resulting strings output to the client.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel -p { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel -p { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } } &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Remove-Tunnel
&lt;/h4&gt; &lt;br /&gt;An added tunnel should clean itself up when the PowerShell console or runspace's process is closed.  Remove-Tunnel can be used to do this beforehand.&lt;br /&gt; &lt;br /&gt;Only one parameter is input (which may be a pipeline input), the tunnel to remove (close).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;Remove-Tunnel $tunnel&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
EmbeddableRunspace
&lt;/h3&gt; &lt;br /&gt;The EmbeddableRunspace folder in the PowerShellTunnel project contains several classes implementing an example hidden or embeddable PowerShell runspace &lt;span class="codeInline"&gt;EmbeddableRunspace&lt;/span&gt; (with no console input or output - though it could be readily extended to log output).  There is nothing special in PowerShellTunnel's implementation of these classes except that there is a useful EmbeddableRunspaceExecute helper class which allows you to easily host a runspace on its own thread and specify what application objects to &lt;i&gt;expose&lt;/i&gt; (make available to the embedded PowerShell runspace as ordinary PowerShell variables).  See the example PowerShellTunnel.Embeddable.Example project to see how this can be done in practice.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
EmbeddableRunspaceExecute.Startup()
&lt;/h4&gt; &lt;br /&gt;Use &lt;span class="codeInline"&gt;Startup()&lt;/span&gt; to start a thread hosting the the embeddable runspace.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
EmbeddableRunspaceExecute.ExposeObject()
&lt;/h4&gt; &lt;br /&gt;Use &lt;span class="codeInline"&gt;ExposeObject()&lt;/span&gt; for each object you want to 'publish' to the hosted runspace, e.g.&lt;br /&gt; &lt;br /&gt;&lt;span class="codeInline"&gt;ExposeObject(&amp;quot;myvar1&amp;quot;, obj)&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;which will set a runspace variable $myvar1 to obj where it will be available for any tunnels.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
EmbeddableRunspaceExecute.AddTunnelHost()
&lt;/h4&gt; &lt;br /&gt;Use AddTunnelHost() to effectively do an Add-TunnelHost (to allow client tunnels to connect to the runspace).&lt;br /&gt; &lt;br /&gt;Use another PowerShell console to tunnel (connect) into the embedded runspace using add-tunnel, and then invoke-tunnel.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
EmbeddableRunspaceExecute.Shutdown()
&lt;/h4&gt; &lt;br /&gt;Use &lt;span class="codeInline"&gt;Shutdown()&lt;/span&gt; to close the embedded runspace and join the thread.&lt;br /&gt; &lt;br /&gt;&lt;h4&gt;
Assumption
&lt;/h4&gt; &lt;br /&gt;As we are using WCF Http by default, we assume that access has been granted (from an admin console), e.g. (note that this only needs to be done once).&lt;br /&gt; &lt;br /&gt;&lt;span class="codeInline"&gt;netsh http add urlacl url=&amp;quot;...your host address...&amp;quot; user=&amp;quot;YOURMACHINENAME\YOURUSERNAME&amp;quot;&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;Note that this embeddable runspace example application requires access to PowerShellTunnel.dll but it does not require that it be installed (it does not use any PowerShellTunnel cmdlets).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Install (SnapIn.cs)
&lt;/h3&gt; &lt;br /&gt;&lt;span class="codeInline"&gt;SnapIn.cs&lt;/span&gt; provides the necessary hooks to allow PowerShell to detect the included cmdlets.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
PowerShellTunnel.Embeddable.Example
&lt;/h2&gt; &lt;br /&gt;PowerShellTunnel.Embeddable.Example.exe is built by compiling the PowerShellTunnel.Embeddable.Example project in PowerShellTunnel.sln.  It is an ordinary Windows console application.  Running the application writes some instructions to the console window and stops by waiting on a Console.ReadLine().  PowerShellTunnel.Embeddable.Example embeds an instance of EmbeddableRunspace and exposes three application objects as PowerShell variables:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$myvar1 = a StringBuilder containing the text 'hi there'
$myvar2 = a DateTime of 2008/1/3
$myvar3 = 45.6 as a decimal data type
&lt;/pre&gt;A tunnel host is hosted at a default address (change this accordingly).&lt;br /&gt; &lt;br /&gt;Note that hosting the EmbeddableRunspace does not need to be on a new thread.  Whether or not you use a separate thread, be aware of threading issues of incoming tunnel client requests (scripts) operating on your exposed objects.  Note that incoming tunnel client requests (scripts) run on WCF threads - normally .NET thread pool worker threads.&lt;br /&gt; &lt;br /&gt;You can then open an ordinary PowerShell console window and Add-Tunnel to connect a running PowerShellTunnel.Embeddable.Example.exe instance's runspace's tunnel host and then Invoke-Tunnel scripts on the application's exposed objects, e.g.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 } 
&lt;/pre&gt;You can set or change variables on the hosted runspace as well as call methods on the objects, and pipe in or out objects in the usual PowerShell way.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 04:09:48 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Reference 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Quick Start</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Quick Start&amp;version=44</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Quick Start
&lt;/h1&gt; &lt;br /&gt;With PowerShellTunnel you create a tunnel between two endpoints: the tunnel 'host' and the tunnel 'client' - you need to start both.  You send scripts from the client to execute on the host as if you had typed them directly into the host (including tab expansion), so you have access to all the objects and capabilities of the host from the client.  Objects can be piped into or out of the tunnel (ordinary serialization is used).&lt;br /&gt; &lt;br /&gt;If you want to follow through the quick start, you'll need to first go through &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Build&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;This quick-start works through two scenarios:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Console -&amp;gt; Console&lt;/b&gt;:  Two PowerShell consoles, one acts as a tunnel host, the other as a tunnel client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Console -&amp;gt; Application&lt;/b&gt;:  One ordinary .NET console application with an embedded PowerShell runspace (which exposes some application objects as ordinary PowerShell variables) which hosts a tunnel, and an ordinary PowerShell console which acts as a tunnel client to interact with the application's objects while the application is running.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h1&gt;
Console -&amp;gt; Console
&lt;/h1&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell console with a couple of objects which we will try to access from another PowerShell console (the tunnel client).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;1-a)	Start a PowerShell console.&lt;br /&gt;	&lt;br /&gt;1-b)	Enter the following commands to add the snapin, add a tunnel host (use the address you specified when you did the install, or refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt; to add an http permission for your user if necessary), and create a couple of ordinary objects:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnelhost = add-tunnelhost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
$x = dir
$y = $x[0]
&lt;/pre&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin and add a tunnel to the tunnel host (using the same address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N{TAB} becomes $y.Name.  The pipeline should work (both in and out) so long as types are WCF-OK (standard types or types made known to WCF &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=...&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;...&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } } &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt;Note: if there are multiple tunnels, then select-tunnel can be used to change the current invoke-tunnel default (and redirect tab expansion), or invoke-tunnel can be called with a '-tunnel xyz' parameter.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 3) Switch back to the host console and verify that you see:
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
write line #1
write line #2
write line #3
&lt;/pre&gt;and verify that $z was created:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$z  #You'll see &amp;quot;This variable is set on the host!&amp;quot;
&lt;/pre&gt;&lt;h3&gt;
Step 4) Switch back to the client console and remove (close) the Tunnel and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-Tunnel $tunnel
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h3&gt;
Step 5) Switch back to the host console and remove (close) the Tunnel Host and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-TunnelHost $tunnelhost
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h2&gt;
Console -&amp;gt; Application
&lt;/h2&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell runspace hosted (embedded) within a console application (PowerShellTunnel.Embeddable.Example.exe) which 'exposes' a few of its objects as PowerShell variables in the hosted runspace.  The client will be an ordinary PowerShell console as before.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;First, if you are re-using the same host address from before, close the tunnel host console from the 'Console -&amp;gt; Console' walkthrough if it is still open.&lt;br /&gt; &lt;br /&gt;Build and run PowerShellTunnel.Embeddable.Example.exe.  This is a console application that outputs some information and waits on a Console.Readline() where pressing Enter exits the application.   A PowerShell runspace is hosted and a tunnel host created in the runspace at address &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot; (or change this value in program.cs).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;	2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N&amp;lt;TAB&amp;gt; becomes $y.Name. The pipeline should work (both in and out) so long as the piped types are serializable.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 }
&lt;/pre&gt;The same kinds of access is available as before with some warnings:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;ol&gt;
&lt;li&gt;The example hosted runspace does not have a console so any scripts which access the console in any way will fail (you can create a more advanced host).&lt;/li&gt;&lt;li&gt;The tunnel host gets its requests on WCF worker threads, so be aware of multi-threading issues on whatever is exposed via the runspace.&lt;/li&gt;&lt;li&gt;Be aware that the client has access to anything that the hosted runspace has.&lt;/li&gt;&lt;li&gt;You may want to configure WCF security in the general case.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
General Notes
&lt;/h2&gt; &lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel Considerations&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 03:50:41 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Quick Start 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Quick Start</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Quick Start&amp;version=43</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Quick Start
&lt;/h1&gt; &lt;br /&gt;With PowerShellTunnel you create a tunnel between two endpoints: the tunnel 'host' and the tunnel 'client' - you need to start both.  You send scripts from the client to execute on the host as if you had typed them directly into the host (including tab expansion), so you have access to all the objects and capabilities of the host from the client.  Objects can be piped into or out of the tunnel (ordinary serialization is used).&lt;br /&gt; &lt;br /&gt;If you want to follow through the quick start, you'll need to first go through &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Build&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;This quick-start works through two scenarios:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Console -&amp;gt; Console&lt;/b&gt;:  Two PowerShell consoles, one acts as a tunnel host, the other as a tunnel client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Console -&amp;gt; Application&lt;/b&gt;:  One ordinary .NET console application with an embedded PowerShell runspace (which exposes some application objects as ordinary PowerShell variables) which hosts a tunnel, and an ordinary PowerShell console which acts as a tunnel client to interact with the application's objects while the application is running.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h1&gt;
Console -&amp;gt; Console
&lt;/h1&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell console with a couple of objects which we will try to access from another PowerShell console (the tunnel client).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;1-a)	Start a PowerShell console.&lt;br /&gt;	&lt;br /&gt;1-b)	Enter the following commands to add the snapin, add a tunnel host (use the address you specified when you did the install, or refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt; to add an http permission for your user if necessary), and create a couple of ordinary objects:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnelhost = add-tunnelhost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
$x = dir
$y = $x[0]
&lt;/pre&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin and add a tunnel to the tunnel host (using the same address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N{TAB} becomes $y.Name.  The pipeline should work (both in and out) so long as types are WCF-OK (standard types or types made known to WCF &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=...&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;...&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } } &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt;Note: if there are multiple tunnels, then select-tunnel can be used to change the current invoke-tunnel default (and redirect tab expansion), or invoke-tunnel can be called with a '-tunnel xyz' parameter.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 3) Switch back to the host console and verify that you see:
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
write line #1
write line #2
write line #3
&lt;/pre&gt;and verify that $z was created:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$z  #You'll see &amp;quot;This variable is set on the host!&amp;quot;
&lt;/pre&gt;&lt;h3&gt;
Step 4) Switch back to the client console and remove (close) the Tunnel and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-Tunnel $tunnel
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h3&gt;
Step 5) Switch back to the host console and remove (close) the Tunnel Host and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-TunnelHost $tunnelhost
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h2&gt;
Console -&amp;gt; Application
&lt;/h2&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell runspace hosted (embedded) within a console application (PowerShellTunnel.Embeddable.Example.exe) which 'exposes' a few of its objects as PowerShell variables in the hosted runspace.  The client will be an ordinary PowerShell console as before.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;First, if you are re-using the same host address from before, close the tunnel host console from the 'Console -&amp;gt; Console' walkthrough if it is still open.&lt;br /&gt; &lt;br /&gt;Build and run PowerShellTunnel.Embeddable.Example.exe.  This is a console application that outputs some information and waits on a Console.Readline() where pressing Enter exits the application.   A PowerShell runspace is hosted and a tunnel host created in the runspace at address &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot; (or change this value in program.cs).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;	2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N&amp;lt;TAB&amp;gt; becomes $y.Name. The pipeline should work (both in and out) so long as the piped types are serializable.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 }
&lt;/pre&gt;The same kinds of access is available as before with some warnings:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;ol&gt;
&lt;li&gt;The hosted runspace does not have a console (there is more and does not have prompting ability, so any scripts which access the console in any way will fail.&lt;/li&gt;&lt;li&gt;The tunnel host gets requests on WCF worker threads, so be aware of multi-threading issues on whatever is exposed via the runspace.&lt;/li&gt;&lt;li&gt;Be aware that the client has access to anything that the runspace has.&lt;/li&gt;&lt;li&gt;You may want to configure WCF security in the general case.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
General Notes
&lt;/h2&gt; &lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel Considerations&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 03:47:14 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Quick Start 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Quick Start</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Quick Start&amp;version=42</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Quick Start
&lt;/h1&gt; &lt;br /&gt;With PowerShellTunnel you create a tunnel between two endpoints: the tunnel 'host' and the tunnel 'client' - you need to start both.  You send scripts from the client to execute on the host as if you had typed them directly into the host (including tab expansion), so you have access to all the objects and capabilities of the host from the client.  Objects can be piped into or out of the tunnel (ordinary serialization is used).&lt;br /&gt; &lt;br /&gt;If you want to follow through the quick start, you'll need to first go through &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Build&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;This quick-start works through two scenarios:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Console -&amp;gt; Console&lt;/b&gt;:  Two PowerShell consoles, one acts as a tunnel host, the other as a tunnel client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Console -&amp;gt; Application&lt;/b&gt;:  One ordinary .NET console application with an embedded PowerShell runspace (which exposes some application objects as ordinary PowerShell variables) which hosts a tunnel, and an ordinary PowerShell console which acts as a tunnel client to interact with the application's objects while the application is running.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h1&gt;
Console -&amp;gt; Console
&lt;/h1&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell console with a couple of objects which we will try to access from another PowerShell console (the tunnel client).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;1-a)	Start a PowerShell console.&lt;br /&gt;	&lt;br /&gt;1-b)	Enter the following commands to add the snapin, add a tunnel host (use the address you specified when you did the install, or refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt; to add an http permission for your user if necessary), and create a couple of ordinary objects:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnelhost = add-tunnelhost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
$x = dir
$y = $x[0]
&lt;/pre&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin and add a tunnel to the tunnel host (using the same address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N{TAB} becomes $y.Name.  The pipeline should work (both in and out) so long as types are WCF-OK (standard types or types made known to WCF &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=...&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;...&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } } &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt;Note: if there are multiple tunnels, then select-tunnel can be used to change the current invoke-tunnel default (and redirect tab expansion), or invoke-tunnel can be called with a '-tunnel xyz' parameter.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 3) Switch back to the host console and verify that you see:
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
write line #1
write line #2
write line #3
&lt;/pre&gt;and verify that $z was created:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$z  #You'll see &amp;quot;This variable is set on the host!&amp;quot;
&lt;/pre&gt;&lt;h3&gt;
Step 4) Switch back to the client console and remove (close) the Tunnel and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-Tunnel $tunnel
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h3&gt;
Step 5) Switch back to the host console and remove (close) the Tunnel Host and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-TunnelHost $tunnelhost
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h2&gt;
Console -&amp;gt; Application
&lt;/h2&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell runspace hosted (embedded) within a console application (PowerShellTunnel.Embeddable.Example.exe) which 'exposes' a few of its objects as PowerShell variables in the hosted runspace.  The client will be an ordinary PowerShell console as before.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;First, close the tunnel host console from the 'Console -&amp;gt; Console' walkthrough if it it still open (we will re-use the same host address for this example).&lt;br /&gt; &lt;br /&gt;Build and running PowerShellTunnel.Embeddable.Example.exe.  This is a console application that outputs some information and waits on a Console.Readline() where pressing Enter exits the application.   A PowerShell runspace is hosted and a tunnel host created in the runspace at address &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot; (if you want to change that address, change the hostAddress constant in program.cs).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;	2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N&amp;lt;TAB&amp;gt; becomes $y.Name. The pipeline should work (both in and out) so long as the piped types are serializable.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 }
&lt;/pre&gt;The same kinds of access is available as before with some warnings:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;ol&gt;
&lt;li&gt;The hosted runspace does not have a console (there is more and does not have prompting ability, so any scripts which access the console in any way will fail.&lt;/li&gt;&lt;li&gt;The tunnel host gets requests on WCF worker threads, so be aware of multi-threading issues on whatever is exposed via the runspace.&lt;/li&gt;&lt;li&gt;Be aware that the client has access to anything that the runspace has.&lt;/li&gt;&lt;li&gt;You may want to configure WCF security in the general case.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
General Notes
&lt;/h2&gt; &lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel Considerations&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 03:40:54 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Quick Start 20080303A</guid></item><item><title>UPDATED WIKI: PowerShellTunnel Quick Start</title><link>http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel Quick Start&amp;version=41</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
PowerShellTunnel - Quick Start
&lt;/h1&gt; &lt;br /&gt;With PowerShellTunnel you create a tunnel between two endpoints: the tunnel 'host' and the tunnel 'client' - you need to start both.  You send scripts from the client to execute on the host as if you had typed them directly into the host (including tab expansion), so you have access to all the objects and capabilities of the host from the client.  Objects can be piped into or out of the tunnel (ordinary serialization is used).&lt;br /&gt; &lt;br /&gt;If you want to follow through the quick start, you'll need to first go through &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Build&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Build&lt;/a&gt; and &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;This quick-start works through two scenarios:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Console -&amp;gt; Console&lt;/b&gt;:  Two PowerShell consoles, one acts as a tunnel host, the other as a tunnel client.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Console -&amp;gt; Application&lt;/b&gt;:  One ordinary .NET console application with an embedded PowerShell runspace (which exposes some application objects as ordinary PowerShell variables) which hosts a tunnel, and an ordinary PowerShell console which acts as a tunnel client to interact with the application's objects while the application is running.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h1&gt;
Console -&amp;gt; Console
&lt;/h1&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell console with a couple of objects which we will try to access from another PowerShell console (the tunnel client).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;1-a)	Start a PowerShell console.&lt;br /&gt;	&lt;br /&gt;1-b)	Enter the following commands to add the snapin, add a tunnel host (use the address you specified when you did the install, or refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20How%20to%20Install&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel How to Install&lt;/a&gt; to add an http permission for your user if necessary), and create a couple of ordinary objects:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnelhost = add-tunnelhost &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
$x = dir
$y = $x[0]
&lt;/pre&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N{TAB} becomes $y.Name.  The pipeline should work (both in and out) so long as types are WCF-OK (standard types or types made known to WCF &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=...&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;...&lt;/a&gt;).&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Examples:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $x }
invoke-tunnel { $y.Name }
$yLocal = invoke-tunnel { $y }; $yLocal # $yLocal is set to a local (serialized &amp;amp; deserialized) copy of $y
invoke-tunnel { $z = &amp;quot;This variable is set on the host!&amp;quot; } 
&lt;/pre&gt; &lt;br /&gt;&lt;i&gt;Example piping objects in and out:&lt;/i&gt;&lt;br /&gt;&lt;span class="codeInline"&gt;&amp;quot;write line #1&amp;quot;, &amp;quot;write line #2&amp;quot;, (&amp;quot;write&amp;quot;, &amp;quot;line&amp;quot;, &amp;quot;#3&amp;quot; ) | invoke-tunnel { $input | foreach { write-host $_; &amp;quot;$_&amp;quot;.Length } } &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;i&gt;Example sending a script file:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;
'$z = 4; $z = $z*$z; write-host &amp;quot;On Host: $z&amp;quot;; &amp;quot;Return to client: $z&amp;quot; ' &amp;gt; test.ps1
type test.ps1 | invoke-tunnel { invoke-expression $input }
del test.ps1
&lt;/pre&gt;Note: if there are multiple tunnels, then select-tunnel can be used to change the current invoke-tunnel default (and redirect tab expansion), or invoke-tunnel can be called with a '-tunnel xyz' parameter.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 3) Switch back to the host console and verify that you see:
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
write line #1
write line #2
write line #3
&lt;/pre&gt;and verify that $z was created:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
$z  #You'll see &amp;quot;This variable is set on the host!&amp;quot;
&lt;/pre&gt;&lt;h3&gt;
Step 4) Switch back to the client console and remove (close) the Tunnel and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-Tunnel $tunnel
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h3&gt;
Step 5) Switch back to the host console and remove (close) the Tunnel Host and remove the snapin.
&lt;/h3&gt; &lt;br /&gt;&lt;pre&gt;
Remove-TunnelHost $tunnelhost
Remove-PSSnapin PowerShellTunnel
&lt;/pre&gt;&lt;h2&gt;
Console -&amp;gt; Application
&lt;/h2&gt; &lt;br /&gt;In this scenario, the tunnel host will be a PowerShell runspace hosted (embedded) within a console application (PowerShellTunnel.Embeddable.Example.exe) which 'exposes' a few of its objects as PowerShell variables in the hosted runspace.  The client will be an ordinary PowerShell console as before.&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 1) Create the Tunnel Host.
&lt;/h3&gt; &lt;br /&gt;First, close the tunnel host console from the 'Console -&amp;gt; Console' walkthrough if it it still open (we will re-use the same host address for this example).&lt;br /&gt; &lt;br /&gt;Build and running PowerShellTunnel.Embeddable.Example.exe.  This is a console application that outputs some information and waits on a Console.Readline() where pressing Enter exits the application.   A PowerShell runspace is hosted and a tunnel host created in the runspace at address &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot; (if you want to change that address, change the hostAddress constant in program.cs).&lt;br /&gt; &lt;br /&gt;&lt;h3&gt;
Step 2) Create the Tunnel Client.
&lt;/h3&gt; &lt;br /&gt;2-a)	Start a PowerShell console.&lt;br /&gt; &lt;br /&gt;2-b)	Enter the following commands to add the snapin, add a tunnel to connect to the above tunnel host (using the address that you used for the host).&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
add-pssnapin PowerShellTunnel
$tunnel = add-tunnel &amp;quot;http://localhost:8000/PowerShellTunnel/Host1&amp;quot;
&lt;/pre&gt;	2-c)	Access the objects on the host.  Note that tab expansion works correctly, e.g. on the Name property of $y, i.e. $y.N&amp;lt;TAB&amp;gt; becomes $y.Name. The pipeline should work (both in and out) so long as the piped types are serializable.&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
invoke-tunnel { $myvar1 }
invoke-tunnel { $myvar2 }
invoke-tunnel { $myvar3 }
&lt;/pre&gt;The same kinds of access is available as before with some warnings:&lt;br /&gt; &lt;br /&gt;&lt;ol&gt;
&lt;ol&gt;
&lt;li&gt;The hosted runspace does not have a console (there is more and does not have prompting ability, so any scripts which access the console in any way will fail.&lt;/li&gt;&lt;li&gt;The tunnel host gets requests on WCF worker threads, so be aware of multi-threading issues on whatever is exposed via the runspace.&lt;/li&gt;&lt;li&gt;Be aware that the client has access to anything that the runspace has.&lt;/li&gt;&lt;li&gt;You may want to configure WCF security in the general case.&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
General Notes
&lt;/h2&gt; &lt;br /&gt;Refer to &lt;a href="http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Considerations&amp;amp;referringTitle=PowerShellTunnel%20Quick%20Start"&gt;PowerShellTunnel Considerations&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;</description><author>MatHobbs</author><pubDate>Mon, 03 Mar 2008 03:39:41 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: PowerShellTunnel Quick Start 20080303A</guid></item></channel></rss>