Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Extract some records from an xml file and save them to another fie

$
0
0

Hello All,

I need to extract some records from an xml file based on some criteria and copy them to another file. I am just stuck on how to save the selected records to another file. grateful if you can help. find powershell script below.

$filelocation="C:\csv"
$files = Get-ChildItem -Path $filelocation

[xml]$xml = get-content $filelocation\$file

    foreach ($x in $xml.ips.MailItem) 
    {
        $itemid=$x.ItemId
        $itemidlength=$x.ItemId.Length
        if ($itemidlength -eq 13)
        {
         $prefix=$x.ItemId.Substring(0,2)
         $suffix=$x.ItemId.Substring(11,2)
            if ($prefix -eq 'RP' -and $suffix -eq 'MU')
                {
                $xml.DocumentElement.AppendChild($x)
                #stuck here
                $xml.Save("C:\csv\test.xml")
                }
        }
    }


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>