<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dynamic binary modules</title><link>http://blogs.msdn.com/b/powershell/archive/2009/07/22/dynamic-binary-modules.aspx</link><description>Using add-type and import-module you can dynamically compile and load an assembly without any intermediate assembly files to cleanup. For instance, to run a cmdlet on a remote machine you could send over the cmdlet source code, compile, import, and run</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Dynamic binary modules</title><link>http://blogs.msdn.com/b/powershell/archive/2009/07/22/dynamic-binary-modules.aspx#9846846</link><pubDate>Fri, 24 Jul 2009 01:18:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9846846</guid><dc:creator>Nigel Sharples</dc:creator><description>&lt;p&gt;Try this to get mycode.cs as a string to preserve the newlines:&lt;/p&gt;
&lt;p&gt;[string]$code = gc mycode.cs | out-string&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9846846" width="1" height="1"&gt;</description></item><item><title>re: Dynamic binary modules</title><link>http://blogs.msdn.com/b/powershell/archive/2009/07/22/dynamic-binary-modules.aspx#9845464</link><pubDate>Thu, 23 Jul 2009 03:26:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9845464</guid><dc:creator>Bob Landau</dc:creator><description>&lt;p&gt;Invoke-Command $s { dir c:\ } # works&lt;/p&gt;
&lt;p&gt;I've tried the code snippet for &amp;quot;dynamic modules&amp;quot; using this code as a test&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/dd901838"&gt;http://msdn.microsoft.com/en-us/library/dd901838&lt;/a&gt;(VS.85).aspx&lt;/p&gt;
&lt;p&gt;while it compiles fine and loads into my session if I do the following by hand&lt;/p&gt;
&lt;p&gt;csc /target:library ./mycode.cs /reference:'C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll'&lt;/p&gt;
&lt;p&gt;Import-Module -Name .\mycode.dll&lt;/p&gt;
&lt;p&gt;Send-Greeting -Name bob&lt;/p&gt;
&lt;p&gt;The same code fails when I execute the following command&lt;/p&gt;
&lt;p&gt;Invoke-Command $s { (Add-Type -TypeDefinition $args[0] -PassThru).Assembly `&lt;/p&gt;
&lt;p&gt;| Import-Module } -ArgumentList $code&lt;/p&gt;
&lt;p&gt;I've tried both &lt;/p&gt;
&lt;p&gt;[string]$code = gc mycode.cs &lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;[string]$code = gc mycode.cs -encoding ascii&lt;/p&gt;
&lt;p&gt;but get the same error &lt;/p&gt;
&lt;p&gt;WARNING: The generated type is not public.&lt;/p&gt;
&lt;p&gt;Cannot bind argument to parameter 'Name' because it is null.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidData: (:) [Import-Module], ParameterBindingValidationException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModul&lt;/p&gt;
&lt;p&gt; &amp;nbsp; eCommand&lt;/p&gt;
&lt;p&gt;does this make any sense to you? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9845464" width="1" height="1"&gt;</description></item></channel></rss>