I reviewed many suggestions posted, but didn't find an exact match. I've created PS scripts where there is one parent script that runs its functions and then calls upon 25 other subscripts in sequence to manage and organize the results of the downloads from the first script.

Currently just one other person I trust, and myself, run this combo of automated PS scripts. There are company changes coming up in the next 6 months that might require other employees to also use these features. I'm in deep need to find a way to transfer this procedure to a Windows friendly secure program. I'm even thinking of requiring unique licensing per program so they can't copy to other users.

Does anyone have some suggestions on what I should research and what to use for this transition? Thank you in advance.

5 Replies 5

You have a few solid options in my opinion:

  1. Wrap PowerShell inside a .NET app (C# + WPF/WinForms)
    Use the PowerShell SDK (System.Management.Automation) to call your scripts from C#.

  2. Compile to EXE
    Use PS2EXE to convert .ps1 files into executables.

  3. Add Licensing / Security

    • Use a .NET licensing library "CryptoLicensing, LimeLM" or check license keys via your server

    • Store sensitive info in Windows Credential Manager or Azure Key Vault

    • Enforce signed scripts only:

      Set-ExecutionPolicy AllSigned
      
      
  4. Deployment
    Package via MSIX or Intune so only authorized employees can install and run it.

In summary:

If you want full control and UI → C# with PowerShell SDK.
If you want a quick conversion → PS2EXE with code signing.

Hope this helps!!!

If the intent is to protect your code to stop people from copying it then that's just not going to be possible. Obfuscation can be very easy to bypass in PowerShell due to things like scriptblock logging and the fact that PowerShell itself needs to parse the plaintext script at runtime to actually produce the code to run. You could migrate the code to compiled languages like C# but decompiling C# binaries is trivial and while there are tools to obfuscate this code there are also tools to help de-obfuscate them. You are starting to move into territory where you need to pay for obfuscation tools and even then it's not guaranteed to work.

If it's to just stopping the casual user from seeing the code and simply copying it then you could use one of the many ps2exe tools out there but I wouldn't recommend it. You are now adding more complexity to the process, most of these tools are flagged by Antivirus tools so you now need to deal with that, and once again someone who really wants to copy the tool can easily do so anyway.

If it's about ensuring the data isn't changed then script signing is an option but that's only really useful if you are validating the file explicitly before running it. People who modify the script can easily just remove the signature to stop it failing there so whatever is calling it either needs to be in an environment where only signed scripts are allowed in run or is manually checking the signature is present and valid before hand.

Honestly if it was me I would keep it as a .ps1, look at script signing if you are in an environment where you can use a trusted CA to sign your script. If you are trying to stop people from just copying the code and not paying you that's a legal issue and not something that can be fixed as a technical issue. You can only make it slightly more inconvenient to the end user to do so but even then it's not that inconvenient.

The only correct answer is: you don't. It is a catch22 rabbit hole. In short, your script shouldn't be used for authorization but the account that runs the script. For example: if your script invokes e.g. a SQL database, that shouldn't be a password based authentication provided by the script but a Windows Authentication (already) provided by the user account that runs the script.
Nevertheless, if you still want to push this through, probably the closest way to "secure" a script is not necessarily obscuring it with a "Windows program" but using DPAPI (Data Protection API) (for each authorized user account) on your own script. See this answer: How to securely store a password for a script run every day using a Windows task scheduler?

In the same spirit as iRon’s comment, I’d suggest thinking outside the box. The real question might be: will these employees actually need to run the scripts, or do they just need to benefit from what the scripts produce?

If the goal is to provide access to the results rather than the process, consider building an automated system around your existing scripts. For example, a central service or scheduled task that monitors a request queue and runs the necessary scripts automatically. It could generate and deposit the final output in a shared location or notify the requester when their results are ready.

This approach removes the need to distribute and secure individual copies of your scripts (and avoids the licensing headache), while also giving you a single, easily maintained version of the process. And if organizational politics come into play, you can present it as a user-friendly “self-service” feature - one that simplifies access and lets you improve or update the workflow for everyone at once.

Have a look at PowerShell JEA (Just Enough Administration). By running sensitive scripts in a JEA session, you set up a strict set of rules of what cmdlets, variables, functions and scripts that can be used by the connecting user (the users also has to be allowed to connect as specified by the JEA config).

So examining the function or script would be blocked by what's allowed according to the JEA config.

At the user front end, you could provide a PowerShell WinForms script with buttons or menus that calls allowed JEA commands (remoting into a bastion host with the active JEA session running). The front end available to the user, would then not contain anything sensitive.

JEA do require some work to get going. But it would isolate your code as per your requst (and the needed permissions to run the code as well) from the user.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.