Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Powershell Pretty Console Output from c#

Powershell has some pretty nifty formating modules for displaying objects, arrays, collections, dictionaries, and tabular data.

Since Powershell is all .NET, I'm assuming there is a Assembly containing the logic for this.

Who can come up with a way to call these powershell formating from .NET:

I'd imagine something like this:

Console.WriteLine(Powershell.DisplayObject(obj))
like image 734
mrbradleyt Avatar asked Dec 14 '25 19:12

mrbradleyt


1 Answers

This is how you do it in V2:

PowerShell.Create().AddScript("get-Process |Out-String").Invoke()

The key thing is to call OUT-STRING.

Experiment! Enjoy! Engage!

Jeffrey Snover [MSFT] Windows Management Partner Architect

like image 129
Jeffrey Snover - MSFT Avatar answered Dec 16 '25 11:12

Jeffrey Snover - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!