Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvertFrom-Clixml should support conversions from files holding multiple Clixml objects #4

Closed
techthoughts2 opened this issue Jan 4, 2020 · 2 comments

Comments

@techthoughts2
Copy link
Contributor

Expected Behavior

When running ConvertFrom-Clixml with a file that contains multiple Clixml objects - the conversion should be able to convert all objects via the pipeline.

$galleryXMLData = Get-Content -Path "C:\xml\all.xml" -Raw
$converted = $galleryXMLData | ConvertFrom-Clixml

Current Behavior

Currently - regardless if -Raw is used or not ConvertFrom-Clixml is only able to convert a file if it contains a singular Clixml object.

Possible Solution

Here is how I am currently working around this:

$galleryData = @()
$galleryXMLData = Get-Content -Path "C:\xml\all.xml" -Raw
$splitup = $galleryXMLData -split '(?<!^)(?=<Objs Version="1.1.0.1" xmlns="http:\/\/schemas.microsoft.com\/powershell\/2004\/04">)'
foreach ($item in $splitup) {
    $galleryData += $item | ConvertFrom-Clixml
}

Steps to Reproduce

  1. Download the Sample XML you can use for testing
  2. Import the file data using Get-Content
  3. Attempt to convert the contents of the data back into PS Object format

Context (Environment)

I have a Clixml file that contains many converted objects. I am attempting to get the contents of the file and convert them back to PowerShell object format. This is working when the file contains one Clixml entry, but not when it contains multiple.

I do currently have a work-around for this which I have shown above.

  • Operating System and version as reported by $PSVersionTable.OS: Microsoft Windows 10.0.18362
  • PowerShell versions as reported by $PSVersionTable.PSEdition: Core

Detailed Description

Based on the behavior it seems like Get-Content doesn't have a delimter available for Clixml data to properly parse it. Because of the lack of delimter the ConvertFrom-Clixml doesn't have a way to handle multiple objects.

This could be handled by introducing a delimeter of some kind when ConvertTo-Clixml is used. Alternatively, logic could be added to permit ConvertFrom-Clixml to handle multi-object conversions.

@austoonz
Copy link
Owner

austoonz commented Jan 5, 2020

Should be resolved in v0.4.1 on the Gallery. Thanks for the regex... leveraged part of that to help! 👍

@techthoughts2
Copy link
Contributor Author

Fix confirmed working. This can be closed out. Thanks for the quick response!

@austoonz austoonz closed this as completed Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants