How to call a script function from a custom module within your C# binary module?

Hi everyone,

I am just beginning my adventure into creating binary modules using .net standard framework. I have been creating script modules for a couple of years now, but want to take it a bit future and start getting my hands “wet” using C# and creating cross-platform modules. Without recreating all existing functions within a script module, is there a way for me to call a function within a script module from my binary module? I have been looking online but have not found any solid examples or nothing really at all. So here I am hoping someone in this awesome community can help me out.

Any help is appreciated! Thanks in advance.

P.S. - If you have any recommendations on creating cross-platform binary modules, please send them my way.

As for… there a way for me to call a function within a script module from my binary module?

… sure, but you have to expose them, via the export. This sort of this is already on your system in the modules/DLL Microsoft already provides. Use DotNetPeek, or other disassembler to view the under the covers stuff.

You don’t show what you’ve tried and what errors you are encountering.
It’s important to show us your work.

This is a fairly common question, function/cmdlet, etc., example:

Using C# to Create PowerShell Cmdlets: The Basics

Writing a PowerShell module in C#, Part 1: The basics

Unit Testing C# binary PowerShell Modules

How to call PowerShell Cmdlet from a binary (C#) module?

If you are looking at cross platform, then your target is only PowerShell Core.
Building modules for PowerShell Core

Hi Postanote,

Thank you for your response & for the links. I did not post any work, because I have not tried anything yet. I have never created a binary module before and have zero experience writing C#, so all of this is brand new territory for me. However, once I do have something put together I can definitely share it.

Are you suggesting I use this dotnetpeek to see how Microsoft might invoke a script function within a binary module? In short, would I using donetpeek to unwrap one of MSFT binary modules (.dlls)?