Run C# code in PowerShell

Ever wanted to run a snippet of C# code in PowerShell? Some times this is useful for testing code in environments without requiring a full deployment of software. This can also be used and an advanced troubleshooting technique. Open a PowerShell Prompt with Elevated permissions. Load your C# class into a string variable C:\Temp>$source = @" public class MathClass { public static int Add(int a, int b) { return (a…

Execute .NET Compiled code from PowerShell

I was troubleshooting some third party software the other day, it was some .NET code that was written by another vendor. Their logging scheme was lacking and the error on the browser side was less than helpful. I was mulling over the problem and the thought occurred to me, can’t I just load the DLL in to PowerShell and start executing methods until I find the problem? After a little…