Powershell: Supported way to load ExtendedTypeDefinition

Created on 22 Sep 2018  路  2Comments  路  Source: PowerShell/PowerShell

PowerShell internally loads format data via the assorted PSControl classes. While that API is public, I haven't been able to find a public way of importing them in an existing runspace.

I was able to export them first with Export-FormatData, but I'm hoping for a way to load them without writing to a file first.

Here's an example of what I'm looking for

// Existing public API
TableControl table = TableControl.Create()
    .AddHeader()
    .AddHeader()
    .StartRowDefinition()
        .AddPropertyColumn("Name")
        .AddPropertyColumn("Description")
    .EndRowDefinition()
.EndTable()

var etd = new ExtendedTypeDefinition(
    "MyModule.MyType",
    new[] { new FormatViewDefinition("Default", table) });

// Pseudo code, not a real API
Runspace.DefaultRunspace.UpdateFormatData(etd, shouldPrepend: false);

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Area-Cmdlets-Utility Issue-Enhancement

Most helpful comment

I don't think there is a way. I've wanted to do the same, but never found a way. We should fix it.

All 2 comments

I don't think there is a way. I've wanted to do the same, but never found a way. We should fix it.

Yeah, this really ought to have parity with Update-TypeData in PS as well. Update-FormatData doesn't accept anything other than file input either.

Was this page helpful?
0 / 5 - 0 ratings