How to run PowerShell script in C# from relative path?

Question:

I’m trying to run a PowerShell script from my C# application. I know how to do so with an absolute path:

What I don’t know how to do is use a relative path. My psScript.ps1 is located in the same directory as my Visual Studio project, and I’d like to use a relative path (such as ./psScript.ps1), so that when I publish/export my project to different computers, the path to the script doesn’t become invalidated

Sooo, how do I use a relative path in the PowerShell.AddScript() method? Any help would be appreciated!

I looked here but this doesn’t answer my question:
PowerShell: Run command from script’s directory

Answer:

Use this:

This path is always relative to the root folder of your project.

Source:

How to run PowerShell script in C# from relative path? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply