Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the output of a PowerShell script?

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.

like image 797
Jens Mühlenhoff Avatar asked Mar 28 '13 16:03

Jens Mühlenhoff


People also ask

How do I read a PowerShell script?

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.

How do I show all outputs in PowerShell?

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 *).

How do I copy the output of a command in PowerShell?

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.


1 Answers

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.

like image 172
Keith Hill Avatar answered Oct 23 '22 06:10

Keith Hill