Skip to content

The CLI's -InputFormat XML processing doesn't work with Export-CliXml output #12376

@mklement0

Description

@mklement0

You can send CLIXML input via the pipeline to the PowerShell CLI, but this currently only works if the input XML file has a #< CLIXML comment line as its very first line, which Export-CliXml does not produce (whereas -OutputFormat Xml does).

Therefore, sending the content of an Export-CliXml-produced fiel currently fails.

Steps to reproduce

'foo' | Export-CliXml tmp.xml
Get-Content tmp.xml | pwsh -noprofile -InputFormat Xml -c '$Input' | Should -Be 'foo'

Expected behavior

The test should succeed.

Actual behavior

The test fails

Expected 'foo', but got $null

If you omit the Should call, you'll see:

Element 'Objs' with namespace name 'http://schemas.microsoft.com/powershell/2004/04' was not found. Line 1, position 4.

Perhaps the following is happening: the first line - expected to the comment line - is blindly skipped, which causes the remaining file content not to be valid XML.

If you manually add the comment line, the test succeeds:

# OK, due to manually prepended comment line.
'#< CLIXML', (Get-Content tmp.xml) | pwsh -noprofile -InputFormat Xml -c '$Input' | Should -Be 'foo'

Environment data

PowerShell Core 7.1.0-preview.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-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