Skip to content

Export-FormatData only exports first view #11825

@ThomasNieto

Description

@ThomasNieto

Export-FormatData only exports first view if the InstanceId is set to a blank guid. I am manually creating ExtendedTypeDefinition objects in order to export to *.format.ps1xml. I was able to workaround the issue by exporting the object to clixml and set a random guid and it exported successfully.

image

Steps to reproduce

Describe 'Export-FormatData' {
    It 'Should be able to export multiple views' {
        $listControl = [System.Management.Automation.ListControl]::Create().StartEntry().AddItemProperty('test').AddItemProperty('test2').EndEntry().EndList()
        $tableControl = [System.Management.Automation.TableControl]::Create().StartRowDefinition().AddPropertyColumn('test').AddPropertyColumn('test2').EndRowDefinition().EndTable()

        $listView = [System.Management.Automation.FormatViewDefinition]::new('Default', $listControl)
        $tableView = [System.Management.Automation.FormatViewDefinition]::new('Default', $tableControl)

        $list = New-Object System.Collections.Generic.List[System.Management.Automation.FormatViewDefinition]
        $list.Add($listView)
        $list.Add($tableView)

        $typeDef = [System.Management.Automation.ExtendedTypeDefinition]::new('TestTypeName', $list)
        $typeDef | Export-FormatData -Path C:\temp\test.format.ps1xml
        [xml]$xml = Get-Content C:\temp\test.format.ps1xml
        @($xml.Configuration.ViewDefinitions.View).Count | Should -BeGreaterThan 1
    }
}

Expected behavior

Test should pass

Actual behavior

Describing Export-FormatData
    [-] Should be able to export multiple views 29ms
      at <ScriptBlock>, C:\Temp\format.tests.ps1: line 16
      16:         @($xml.Configuration.ViewDefinitions.View).Count | Should -BeGreaterThan 1
      Expected the actual value to be greater than 1, but got 1.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.2
PSEdition                      Core
GitCommitId                    7.0.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions