I want to add PowerShell capabilities to a C# program and
I have embedded the system.managment.automation.dll
assembly as a reference.
I have found on StackOverflow two ways to call a PowerShell scrit from C# :
Using runspaces:
Not using runspaces:
PowerShell powerShell = PowerShell.Create(); powerShell.AddScript("my script"); powerShell.Invoke();
According to this website, it seems the Powershell instance is tied to its C# host.
The Powershell runtime is invoked as a runspace and will, by default, process commands synchronously and deliver the results of processing to the host application so that they can be returned to the user.
Furthermore, the PowerShell script uses the embedded system.managment.automation.dll
assembly and not the system-wide one, so the script would logically stop with its C# host.
Does the Powershell script would still run after the user close my program ? What about the two methods ?
PS: I want to support PowerShell v2.