mrbradleyt
mrbradleyt

Reputation: 2364

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

Upvotes: 3

Views: 2293

Answers (3)

slipsec
slipsec

Reputation: 3062

This might not be where you are going here but check out the Extended Type System.

Here's a good spot to start: msdn PS blog blog

Upvotes: 0

karl prosser
karl prosser

Reputation:

you might want to control the width of the output with | out-string -width 120 for instance.

Upvotes: 1

Jeffrey Snover - MSFT
Jeffrey Snover - MSFT

Reputation: 10253

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

Upvotes: 7

Related Questions