{"id":4891,"date":"2009-01-02T19:26:56","date_gmt":"2009-01-02T19:26:56","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/01\/02\/how-to-write-a-console-application-in-powershell-with-add-type\/"},"modified":"2019-02-18T13:12:59","modified_gmt":"2019-02-18T20:12:59","slug":"how-to-write-a-console-application-in-powershell-with-add-type","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/how-to-write-a-console-application-in-powershell-with-add-type\/","title":{"rendered":"How To Write a Console Application in PowerShell with Add-Type"},"content":{"rendered":"<p>Windows PowerShell CTP3 has a lot of very cool things.&#160; CTP2 introduced the Add-Type cmdlet, which allowed you to dynamically compile C# in PowerShell.&#160; It was actually possible to use the CompilerParameters to Add-Type to make a console application, but it wasn&#8217;t particularly easy.&#160; In CTP3, we&#8217;ve made this a lot easier to do.<\/p>\n<p>There&#8217;s now an -OutputType parameter for Add-Type.&#160; It can either output a Library (the default), a ConsoleApplication, or a WindowsApplication.&#160; Check out this really quick &quot;Hello World&quot; program built using Add-Type.<\/p>\n<p class=\"PowerShellColorizedScript\"><span style=\"color: #0000ff\">Add-Type<\/span>&#160;<span style=\"color: #000080\">-OutputType<\/span>&#160;<span style=\"color: #8a2be2\">ConsoleApplication<\/span>&#160;<span style=\"color: #000080\">-OutputAssembly<\/span>&#160;<span style=\"color: #8a2be2\">HelloWorld.exe<\/span>&#160;<span style=\"color: #8b0000\">@&quot;      <br \/>using System;       <\/p>\n<p>public class MyProgram       <br \/>{       <br \/>&#160;&#160;&#160; public static void Main(string[] args) {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Hello World&quot;);       <br \/>&#160;&#160;&#160; }       <br \/>}       <br \/>&quot;@<\/span><\/p>\n<p>Hope this Helps, <\/p>\n<p>James Brundage [MSFT]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows PowerShell CTP3 has a lot of very cool things.&#160; CTP2 introduced the Add-Type cmdlet, which allowed you to dynamically compile C# in PowerShell.&#160; It was actually possible to use the CompilerParameters to Add-Type to make a console application, but it wasn&#8217;t particularly easy.&#160; In CTP3, we&#8217;ve made this a lot easier to do. There&#8217;s [&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":[96,137,4],"class_list":["post-4891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-add-type","tag-ctp3","tag-howto"],"acf":[],"blog_post_summary":"<p>Windows PowerShell CTP3 has a lot of very cool things.&#160; CTP2 introduced the Add-Type cmdlet, which allowed you to dynamically compile C# in PowerShell.&#160; It was actually possible to use the CompilerParameters to Add-Type to make a console application, but it wasn&#8217;t particularly easy.&#160; In CTP3, we&#8217;ve made this a lot easier to do. There&#8217;s [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4891","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=4891"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4891\/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=4891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}