A while ago the Windows Powershell Blog described a function to generate xml on the fly. Here is the v1 version of the function I often use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function Emit-XML { BEGIN { @" <?xml version="1.0" encoding="utf-8" ?> <Objects> "@ } PROCESS { $object = $_ $objectproperty = ($object | get-member -type *Property) "<Object>" foreach ($p in $objectproperty) { $Name = $p.Name $Value = $Object.$Name "`t<$Name>$Value</$Name>" } "</Object>" } END { @" </Objects> "@ } } |