Windows PowerShell Home
Export-Clixml exports members of a collection, not the collection itself
3/4/2013 6:43:11 AM
User(s) can reproduce this bug
When exporting an arraylist via Export-Clixml, the resulting xml file only contains the description of members of the arraylist. The collection type is lost during exportation.
How often does this happen?
Have you seen this problem before in this product?
Yes, this happens in previous released versions
$coll = new-object System.collections.arraylist
$null = $coll.add("firstElement")
$coll | export-clixml $home\test.xml
$coll = import-clixml $home\test.xml
$null = $coll.add("secondElement")
# Causes the following exception:
Method invocation failed because [System.String] doesn't contain a method
# $coll.gettype() returns String
The imported object should still be a collection.
$coll.add("secondElement") should succeed.
to post a comment.
Please enter a comment.
on 5/31/2013 at 12:49 PM
That's how *all* collections behave when piped to another cmdlet. Export-Clixml will never see your arraylist.
If you want to have it in resulting XML you can:
* use unary comma: , $col | Export-Clixml
* use -InputObject parameter: Export-Clixml -InputObject $col
to post a workaround.
Please enter a workaround.
© 2013 Microsoft