I'm having some difficulty removing nodes from an xml file. I've found lots of examples of others doing this in powershell through various means, the code below would seem to be identical to many of the other examples I've seen, but I'm not getting the desired behavior.
My goal is to reduce the size of the output XML until it's below 4KB.
The code below doesn't error out, but the count of objects in $updateactivity never changes, so the node doesn't seem to be removing.
This is a log in xml format, so I'm removing the oldest entries first.
sample xml:
<?xml version="1.0" encoding="utf-16"?>
<LogEntries version="1.0" appname="Dell Command | Update" appversion="4.3.0">
<LogEntry>
<serviceVersion>2.3.0.36</serviceVersion>
<appname>DellCommandUpdate</appname>
<level>Normal</level>
<timestamp>2022-01-07T13:29:57.9364469-08:00</timestamp>
<source>UpdateScheduler.UpdateScheduler.Start</source>
<message>Starting the update scheduler.</message>
<trace/>
<data/>
</LogEntry>
</LogEntries>
code:
[xml]$dcuxml = get-content "C:\ProgramData\dell\UpdateService\Log\Activity.log"
$xmllog = $dcuxml.LogEntries
$update_activity = $xmllog.LogEntry | NotableDCU
$i = 0
Do{
foreach($entry in $update_activity){
$entry.parentnode.RemoveChild($entry)
$xmlsize = [System.Text.Encoding]::UTF8.GetByteCount(($update_activity.InnerXml | Out-String)) / 1KB
}
}while($xmlsize -gt 3.99)