Microsoft – PowerShell – Inline C# – Error – This file does not have a program associated with it for performing this action

Having a bit of fun with PowerShell lately.

As part of the playing aound, needed or more like wanted to incorporate C#:

As example:

    Add-Type -OutputType ConsoleApplication -OutputAssembly HelloWorld.exe @"

      using system;

      public class helloWorld
      {

            public static void Main(string[] args)
            {

                  Console.WriteLine("Hello World");

            } 

      }

    "@

But, kept getting an Error Message that read:

Message Box Title:

Explorer.Exe

Message Box Content:

This file does not have a program associated with it for performing this action.
Please install a program or, if one is already installed, create an association in the Default Programs control panel.

After hours of battling with it, I thought more about what might be possible reasons.

And, tried to figure out how Powershell is magically able to use C#; C# source code for

that matter.

The question seemed more likely how does Managed Code (.Net) get translated to

Compiled Code (.exe, .dll).  And, later consumed by PowerShell.

It seemed likely that a Common Line Compiler (ie csc) comes into play.  That is csc along

with whatever libraries are referenced are used in building the resulting managed code.

As the box is MS Windows 2008, use Server Manager and determine whether .Net

Framework (3.5.1) in our case is included as a feature.

In our case, it appeared that Microsoft .Net v3.5 was already installed and enabled.

But, nevertheless, we are now able to “consume” .Net C# source code.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s