Hey guys I am newish to C#. I know powershell. I am trying to figure out how to run a powershell script from a c# program. I have below working as a test program for myself. However when i try and put in more complex scripts ones that can include GUI windows that should pop up nothing seems to run. Am i on the right track to figuring this out? I have also noticed that the semi colon after each line was needed to run the script correctly in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (PowerShell PS = PowerShell.Create())
{
PS.AddScript("$file = \"C:\\test\\csharp.txt\";"+
"Set-Content -path $file -value \"testc\";");
PS.Invoke();
}
}//end of main
}//end of class
}//end of namespace