[xml]$xml = Get-Content "sysmonconfig.xml"
# Remove all existing NetworkConnect and DnsQuery
$xml.SelectNodes("//NetworkConnect") | ForEach-Object { [void]$_.ParentNode.RemoveChild($_) }
$xml.SelectNodes("//DnsQuery") | ForEach-Object { [void]$_.ParentNode.RemoveChild($_) }
# Create a new RuleGroup
$ruleGroup = $xml.CreateElement("RuleGroup")
$ruleGroup.SetAttribute("name", "AggressiveNetwork")
$ruleGroup.SetAttribute("groupRelation", "or")
$netNode = $xml.CreateElement("NetworkConnect")
$netNode.SetAttribute("onmatch", "exclude")
$netNode.InnerXml = "127.0.0.1127.0.0.1192.168.10."
[void]$ruleGroup.AppendChild($netNode)
$dnsNode = $xml.CreateElement("DnsQuery")
$dnsNode.SetAttribute("onmatch", "exclude")
$dnsNode.InnerXml = ".arpa.local"
[void]$ruleGroup.AppendChild($dnsNode)
[void]$xml.Sysmon.EventFiltering.AppendChild($ruleGroup)
$xml.Save("sysmon_tuned.xml")