I would like to execute and capture the output of a very simple powershell script. Its a "Hello World" script and it looks like this. I used this post for reference
filename:C:\scripts\test.ps1
Write-Host "Hello, World"
Now I would like to execute that script using C# so I am doing this
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.Commands.AddScript(filename);
Collection<PSObject> results = ps.Invoke();
Now when I run this code, I get nothing in results. Any suggestions on how I can resolve this issue?