views:

203

answers:

1

Dear Friends,

I am developing a .NET/C# 2.0 application which uses the PowerShell SDK for script execution. I am not using SnapIns. I am setting everything directly through PS's RunspaceConfiguration.

So my problem is that I cannot add a custom format for my type Plux.ExtensionTypeInfo implemented in the application.

( Plux.ExtensionTypeInfo has a property called Name )

That is what I try:

...
RunspaceConfiguration config = RunspaceConfiguration.Create();

config.Formats.Prepend(
    new FormatConfigurationEntry("plux.format.ps1xml")
    );

config.Formats.Update();
...

plux.format.ps1xml:

<Configuration>
  <ViewDefinitions>
  <View>
       <Name>Plux.ExtensionTypeInfo</Name>
            <ViewSelectedBy>
                <TypeName>Plux.ExtensionTypeInfo</TypeName>
            </ViewSelectedBy>
            <TableControl>
                <TableHeaders>
                    <TableColumnHeader>
                        <Width>30</Width>
                    </TableColumnHeader>
                </TableHeaders>
                <TableRowEntries>
                    <TableRowEntry>
                        <TableColumnItems>
                            <TableColumnItem>
                                <PropertyName>Name</PropertyName>
                            </TableColumnItem>
                        </TableColumnItems>
                    </TableRowEntry>
                </TableRowEntries>
            </TableControl>
        </View>
</ViewDefinitions>
</Configuration>

After executing a Cmdlet, which returns a few ExtensionTypeInfo objects, the output will never be formatted.

With the built in Cmdlets and Types, the formatting works perfectly in my PS Host application. The Cmdlet registration works also fine through the config object. When launching update-formatdata on plux.format.ps1xml, with powershell.exe or my hosting application, no errors are thrown.

Still, the code above has no effect on formatting.

A: 

I haven't tried hosting the PowerShell runtime environment. But I am pretty sure that your issue is that the output formatting isn't happening because you are capturing the pipeline in your application, rather than in the PowerShell host.

Output formatting happens in the Out-Default cmdlet in the PowerShell host, or by calling Format-Table or Format-List to specify a format.

EDIT:

My suggestion would be to run this in the runspace.

YourCommand | Format-Table Name | Out-String

Also, I hope you aren't trying to parse this output.

JasonMArcher
(Sorry for the late answer, I was out of office)Yes, I indeed append out-string to every pipeline before executed. So the default formatting works pretty well.