I'm trying to write a small Powershell function that will return some summary data from some XML log files. I wrote a short summarizing function:
function Summarize-Log( $log )
{
$obj = New-Object Object
$obj | Add-Member NoteProperty Date $log.lastwritetime
$obj | Add-Member NoteProperty Passed ([xml](get-content $log)).suite.passed
$obj | Add-Member NoteProperty NotImplemented ([xml](get-content $log)).suite.notImplemented
return $obj
}
I think I should be able to call this function like this:
dir -recurse $logDirs | where { $_.name -eq "MyLog.xml" } | foreach{ Summarize-Log $_ }
When I call it like this, it seems to read the SAME numbers out of each pass through the loop. The Date property is correct, but the two properties being read from the XML are incorrect, as if the get-content call is returning the same data regardless of the input parameter.
How do I fix this?
Right now it appears from the code as if the whole file will be read in twice. Is there a more efficient way to get this information?