Monday, December 13, 2010

Using XML Namespaces in PowerShell

$xpath = @{
    Start="//e:data[@name = 'BootStartTime']/text()"
    End="//e:data[@name = 'BootEndTime']/text()"
}

$ns = New-Object Xml.XmlNamespaceManager $xml.NameTable
$ns.AddNamespace( "e", "http://schemas.microsoft.com/win/2004/08/events/event" )

[DateTime]$Start = $xml.SelectSingleNode( $xpath.Start, $ns ).Value
[DateTime]$End   = $xml.SelectSingleNode( $xpath.End, $ns ).Value

($End - $Start).ToString() # Displays: 00:03:11.7917783

Via.

No comments: