Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Powershell Script to C# project

Tags:

c#

powershell

So I'm fairly new to programming so hoping someone can help me out here. I'm building a C# application that requires a powershell script, now whilst I know how to call the script using Runspaces and Pipeline, this method requires referencing the scripts location within the code, which will pose a problem if this application is to be used by someone else besides myself. Does anybody know if there is a way to add a powershell script to a project so it can be referenced instead of me having to reference a file location?

like image 650
user3628287 Avatar asked Jun 16 '26 00:06

user3628287


1 Answers

There are a two things that come to mind:

  1. Inline your Powershell script in C# (Use StringBuilder to build your powershell script).
  2. Embed your powershell script as a text resource and read it as a stream, execute it. Reference here.
like image 188
Srikanth Venugopalan Avatar answered Jun 18 '26 12:06

Srikanth Venugopalan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!