How to access the output of a PowerShell script in Delphi?
I'm looking for something similar to System.Management.Automation.PowerShell, but in native code.
To be more precise: I'd like to process the PSObject
objects returned by a PowerShell invokation.
I guess since the PowerShell is written in .NET I'd have to host the .NET framework in my Delphi application?
I've seen a library called PowerShell Objects Delphi Edition on component source, but the demo doesn't support XE2 and I can't find the library on the manufaturers homepage.
Clarification: I'm not looking for a way to run the PowerShell, CreateProcess works fine for this.
When you want to read the entire contents of a text file, the easiest way is to use the built-in Get-Content function. When you execute this command, the contents of this file will be displayed in your command prompt or the PowerShell ISE screen, depending on where you execute it.
Utility) - PowerShell. The Format-List cmdlet formats the output of a command as a list of properties in which each property is displayed on a separate line. You can use Format-List to format and display all or selected properties of an object as a list (Format-List -Property *).
Just select the text in the console window and press enter or the right mouse button. That selected text ends up in your clipboard. Note that this will only work if QuickEdit mode is enabled for the console window.
You could create a C++/CLI wrapper around System.Management.Automation.* and expose a DLL entry point like string ExecutePowerShellScript(string script)
. Then you should have no problem invoking that DLL entry point from Delphi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With