Quantcast
Channel: get-command | PowerShell » XML
Viewing all articles
Browse latest Browse all 3

Emit-XML (powershell v1)

$
0
0

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>
"@
}
}

Viewing all articles
Browse latest Browse all 3

Trending Articles