0

So I'm looking for a way to convert .ps1 scripts(using an online tool or whatever that works) to string format so that I can just copy and paste it into my C# code in a string variable.

This will enable me to stop referencing the paths of my scripts in the code as these may change from one computer/user to another.

Thanks!

13
  • 1
    I would suggest you put the script in some shared folder and read the file from C# code. And define the shared folder path in config file so that it will be easy to change it later Commented Jan 30, 2022 at 12:03
  • 2
    I think you better convert it to a base64 string and execute it with powershell.exe -EncodedCommand $encodedcommand see devblogs.microsoft.com/scripting/… Commented Jan 30, 2022 at 12:04
  • 1
    Does this answer your question? Convert PowerShell script into non-readable format Commented Jan 30, 2022 at 12:06
  • @viveknuna Thanks, I thought about this, especially the fact that I could easily change it later. But in the case where the users are using a different computer, can a share file still be used? Sorry if the question is dumb I'm very new to this. Commented Jan 30, 2022 at 12:09
  • @Avshalom Thanks I'm gonna take a look into this Commented Jan 30, 2022 at 12:09

1 Answer 1

1

base64 encode and decode

I would use this solution: https://www.base64encode.org/ You can also test the string... with the decode link: https://www.base64decode.org/

I am sure in C# you have also base64decode to reconvert into PS1.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow thanks, I'll take a look into this

Your Answer

By clicking “Post Your Answer”, 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.