locked
Compile an powershell script to DLL RRS feed

  • Question

  • Hi,

    I have some powershell functions I would like to embed in an .dll file I can share with my teams.
    I think that .dll is a good choice, because no one can edit the code and for security reason, nobody can read the code without specfic tools.

    How Can I compile my .ps1 in an dll I could use for batch script after?

    The only way I find is to create an C# project and embed my powershell script in to make my .dll.

    Regards

    Friday, November 17, 2017 1:32 PM

Answers

  • I was pretty sure it wasn't possible, but I'll prefer asking an question instead of not.

    Finally, my scripts need to be more than simple powershell script, so If I need to make an dev for making actions on my AD; I will.

    If Powershell could be compile in an DLL I could use from another powershell, I won dev times, but it's not.
    So ok, I'll develop an C# project et I'll use it from an very simple script PS..

    You don't know how and for what I use powershell, so your answer is correct, now I'm sure that .net will be useful for some needs..

    • Marked as answer by Frédéric.G Thursday, November 23, 2017 2:28 PM
    Monday, November 20, 2017 2:46 PM

All replies

  • I believe C# is easy to disassemble.

    Friday, November 17, 2017 4:06 PM
  • You cannot compile PowerShell into a DLL. You can write a DLL in C# or other Net language and use it from PowerShell.  You can also create binary module in a compiled Net language jst like many of the current PowerShell modules.'  See the PowerShell SDK for examples.

    https://technet.microsoft.com/en-us/library/ff458115.aspx

    The first thing you need to do is learn PowerShell.  All of this would be obvious and useful if you take the time to formally learn PowerShell.


    \_(ツ)_/

    Friday, November 17, 2017 4:23 PM
  • if you want to make it unreadable , go with ps2Exe , this will give you an EXE .

    Regards kvprasoon


    Sunday, November 19, 2017 2:58 AM
  • ps2Exe

    Regards kvprasoon

    This does not create DLLs.  You asked about DLLs.  Yes, most of us know about Ps2Exe.


    \_(ツ)_/

    Sunday, November 19, 2017 3:15 AM
  • yup, I forgot to mention that, his intention was to make it unreadable for others, so proposed ps2exe.

    Regards kvprasoon

    Sunday, November 19, 2017 5:14 AM
  • Read - "I have some powershell functions I would like to embed in an .dllfile"

    The OP may be a bit confused about what a DLL is.


    \_(ツ)_/


    • Edited by jrv Sunday, November 19, 2017 5:57 AM
    Sunday, November 19, 2017 5:56 AM
  • I was pretty sure it wasn't possible, but I'll prefer asking an question instead of not.

    Finally, my scripts need to be more than simple powershell script, so If I need to make an dev for making actions on my AD; I will.

    If Powershell could be compile in an DLL I could use from another powershell, I won dev times, but it's not.
    So ok, I'll develop an C# project et I'll use it from an very simple script PS..

    You don't know how and for what I use powershell, so your answer is correct, now I'm sure that .net will be useful for some needs..

    • Marked as answer by Frédéric.G Thursday, November 23, 2017 2:28 PM
    Monday, November 20, 2017 2:46 PM
  • Hi,

    I'm checking how the issue is going, was your issue resolved?

    And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Frédéric.G Thursday, November 23, 2017 2:28 PM
    • Unmarked as answer by jrv Thursday, November 23, 2017 2:36 PM
    Tuesday, November 21, 2017 4:09 AM
  • With the PS Protector it is possible to convert a PowerShell module (.psm1) into a DLL. The tool is easy to use and you do not need C # knowledge.

    See here for more information: https://www.psprotector.com


    • Edited by Stefan Soller Thursday, February 28, 2019 10:24 PM Link Edit
    Thursday, February 28, 2019 10:23 PM