The Export-CliXml
command should offer a parameter set that emits a string, instead of writing the result to a file. Right now, it only supports outputting CLIXML to a file via the -Path
or -LiteralPath
parameters.
Cheers,
Trevor Sullivan
Given how this distinction is handled in existing cmdlets (e.g., Export-Csv
/ ConvertTo-Csv
), that would probably call for a new cmdlet named ConvertTo-CliXml
, plus a matching ConvertFrom-CliXml
.
Struggling to see the use case for Clixml representation of a an object just in memory. The CliXml cmdlets, as I understand them, are about persisting objects
There are many different places you might want to persist objects. The filesystem is just one place.
Just came across a decent use case for this...
Environment variables currently on take strings, so storing a complex object as an environment variable is not really possible. But if Export-Clixml could export a string to an environment variable, then we could relatively easily use Import-Clixml to re-hydrate the object.
If this followed the convention of CSV, it would actually be better to have a ConvertTo-Clixml
cmdlet as well as a ConvertFrom-Clixml
One reason I could think of this as useful is to pass the persisting object to things other than files, such as network streams or as body data in HTTP without needing to write to a file first.
Building on top of what @markekraus mentioned, another use case would be sending the CLIXML off to a message queue for processing by a different consumer application. I should not have to write the CLIXML to disk, and then read it again, to accomplish this.
@powershell/powershell grabbing, if i can?
Progress on this: https://github.com/charlieschmidt/PowerShell/tree/powershell-3898-convertfromto-clixml
I'll get the tests & docs added this weekend and do a proper PR
As a simple workaround how about this...
`$SerializedString = [System.Management.Automation.PSSerializer]::Serialize($Object)
$BackToObject = [System.Management.Automation.PSSerializer]::Deserialize($SerializedString)`
It's a _viable_ workaround, but I wouldn't call it _simple_, because this behind-the-scenes type is neither widely known nor easy to remember.
As an aside: Serialize()
defaults to depth 1
, whereas Export-CliXml
defaults to depth 2
.
I like to work on this issue. I hope that the cmdlets are still needed.
I see there was an old PR that never got merged and is now closed... but yeah we can still use this. Go for it! 馃檪
Most helpful comment
Given how this distinction is handled in existing cmdlets (e.g.,
Export-Csv
/ConvertTo-Csv
), that would probably call for a new cmdlet namedConvertTo-CliXml
, plus a matchingConvertFrom-CliXml
.