Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute the powershell code with another method
#4
Seeing as PowerShell and C# are both .NET languages, the interop here should be pretty easy and based on the exchange of rich .NET types instead of string output. For example, calling Get-Process should return an array of System.Diagnostics.Process objects that I can work with in my C# application.

Rather than calling PowerShell as an external program, using run.console, I think it would be better to host Windows PowerShell (or PowerShell 7, if you have the Microsoft.PowerShell.SDK installed ) in your C# application using the instructions provided by MSFT here: https://docs.microsoft.com/en-us/powersh...rshell-7.2

I think it would be great if QM3 had a PSRun command that abstracted away some of the complexity of hosting a PowerShell runspace. I wasn't able to get QM3 to work with Windows PowerShell 5.1 (maybe because they are based on different version of .NET?) nor could I get it working with PowerShell 7, presumably due to the missing files Gintaras mentioned. 

These 2 languages could really compliment each other in a product like QM3, so working with them together with little difficulty would be amazing.

@Gintaras - Speaking of interop between QM3 and PowerShell, do you know if it is possible to go the other way, calling QM3 from PowerShell. Something like this? That would be pretty cool too...
 
Code:
Copy      Help
Add-Type -Path "C:\PathTo\Au.dll" 

# Create object of CustomClass 
$folderObj = New-Object Au.folders 

# Calling getFolder method 
$tempFolder = $folderObj.getFolder("temp")


Messages In This Thread
RE: Execute the powershell code with another method - by outnull - 08-11-2022, 03:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)