做了许多的文本转对象,都是split或regex来实现,以前听说过文本转XML的功能,前几天做了觉得确实不错,上代码。
先上一个有点炫技的:
$xmlMessage=(Get-WinEvent -FilterHashtable @{Logname="Microsoft-Windows-WLAN-AutoConfig/Operational";Id='8001'} |
select $_.Message)| foreach {$_.toxml() }
$lists=New-Object System.Collections.ArrayList
foreach($item in $xmlMessage){
$textxml=New-Object system.xml.XmlDocument
$textxml.LoadXml($item)
$Property=@{"TimeCreated"=[datetime]::Parse($textxml.Event.System.TimeCreated.SystemTime).tostring("yyyyMMdd-hhmmss")}
$textxml.Event.EventData.ChildNodes|foreach{
$Property+=@{$_.name=$_."#text"}
}
$row=""| select ($Property.Keys|foreach {$array=@()}{$array+=,$_}{$array})
foreach($p in $Property.Keys){
$row.$p=$Property[$p]
}
$null=$lists.add($row)
#return
}
$lists[0]
$lists|select InterfaceGuid,SSID,TimeCrea