I don't think you can get there with ConvertTo-Xml
. However, you can use here strings
to do this. It is kind of low tech but still pretty cool:
$hash = @{
Processor = 'Intel'
Disk = '500GB'
Server = 'ABC'
Serial = '01234'
}
@"
<Objects>
<Object>$(foreach ($kvpair in $hash.GetEnumerator()) {
"`n <$($kvpair.Key)>$($kvpair.Value)</$($kvpair.Key)>"
})
</Object>
</Objects>
"@ > C:\scripts\export.xml
You could use the XML DOM
to create this document but that would be more work and for such a simple document I think the here string
approach works pretty well. It is also good for any sort of text templating.