Illustration de l'article

Reading xml from PowerShell is really easy!

Écrit par Luc

It is amazing to see how simple we can read xml node values from powershell:

Here is a peace of xml file

<?xml version="1.0" standalone="yes"?>

PowerShell converts XML elements to properties on .NET objects without the need to write any parsing code!

$coverageFileXml = C:tempmyCoverageInfo.xml
[xml]$xml = (get-content $coverageFileXml)
[int]$BlocksCovered = $xml.CoverageDSPriv.Module.BlocksCovered
[int]$BlocksNotCovered = $xml.CoverageDSPriv.Module.BlocksNotCovered
[int]$TotalBlocks = $BlocksCovered + $BlocksNotCovered
$CoveragePercent = $BlocksCovered \* 100 / $TotalBlocks
$CoveragePercent2Decimals = "{0:N2}" -f $CoveragePercent
Write-Host "Coverage is $CoveragePercent2Decimals %"

Output is : Coverage is 48.62 %

More exemples here.

Illustration de l'article
comments powered by Disqus