Copying compiled C# code originally written in PowerShell.

My understanding of PowerShell is that since 3.0, advanced functions written in PowerShell are ultimately compiled and executed in C#. Is there a means by which I can inspect or copy the compiled C# equivalent of code I’ve authored in PowerShell?

That’s not quite how it works. Your PowerShell code gets compiled down to a .NET expression tree in the DLR (see https://msdn.microsoft.com/en-us/library/bb397951.aspx?f=255&MSPPError=-2147217396 ). It’s not the same as translating PowerShell code into useful C# that you could copy.

I’m not a developer, say don’t take anything granted I will say to you.

But you need a .NET reflector tool for this. Something like .NET Decompiler: Decompile Any .NET Code | .NET Reflector

Then use this function (yes, this code is from 2008 but still works): http://www.nivot.org/post/2008/10/30/ATrickToJumpDirectlyToACmdletsImplementationInReflector

It’s a bit tedious work, but I’m not aware of other methods to do it. :slight_smile: