'Best way to call and access powershell script in ASP.NET Core project

I have a PowerShell script which I have to call in an ASP.NET Core Web API solution.

What is the best way to use the PowerShell script in an ASP.NET Cre Web API solution?

Should I add the PowerShell script as a string constant in a class or add a PowerShell script in the project solution (source control) and then maybe using AppContext.BaseDirectory get the path and then use it?

I am sorry that this is not a programming question since I just needed a suggestion of what will be the correct way to implement the same.

Thanks



Solution 1:[1]

I think the method you mentioned is feasible, but not necessarily the best. The reason is that when we find the script file, we let the server execute the script, and we cannot quickly locate the events or exceptions during execution.

It seems that we can use some class libraries (such as Microsoft.PowerShell.SDK), we can store the script content in the database, and execute these scripts in the asp.net core program. It should be possible to get status or return information at every step of execution, which may be more friendly.

Related Blog: How to run PowerShell Core scripts from .NET Core applications

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason