Question about ConvertTo-XML

Topics: User Forum
Jun 16, 2009 at 9:28 PM

How can I get ConvertTo-XML to use the property name for the container name?
<Property Name="country">USA</Property>

After some disappointment with the output of Export-Clixml, I found the
ConvertTo-XML Cmdlet included with the great PSCX tools.

This has cleaned up my output greatly.

Initial Export-Clixml output:

<?xml version="1.0" encoding="utf-16"?>
<Objs Version="" xmlns="">
  <Obj RefId="0">
    <TN RefId="0">
      <S N="title">Empire Burlesque</S>
      <S N="artist">Bob Dylan</S>
      <S N="country">USA</S>
      <S N="company">Columbia</S>
      <S N="price">10.90</S>
      <S N="year">1985</S>

ConvertTo-XML -NoTypeInformation ouput:

    <Property Name="title">Empire Burlesque</Property>
    <Property Name="artist">Bob Dylan</Property>
    <Property Name="country">USA</Property>
    <Property Name="company">Columbia</Property>
    <Property Name="price">10.90</Property>
    <Property Name="year">1985</Property>

Desired output:

    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>

The only answer I have found that gets close is here:

However, this code for Emit-XML doesn't use ConvertTo-XML, only exports the final object.

Thanks for any guidance you may be able to give a powershell newbie


Jun 19, 2009 at 10:35 PM

I think you've got a good answer with the Emit-xml blog post approach.  BTW the ConvertTo-Xml cmdlet is part of PowerShell V2.  There is a similar PSCX cmdlet - Convert-Xml - but it is for applying XSL transforms.