I have some file .sfu, I would like to check the sum and get some information to write to XML file. I try this way but still can not get the expected xml file.
$File = Get-ChildItem -Path .\*B01-A1* -Filter *.sfu
$Path = ".\SUM.xml"
# get an XMLTextWriter to create the XML
$XmlWriter = New-Object System.XMl.XmlTextWriter($Path,$Null)
# choose a pretty formatting:
$xmlWriter.Formatting = 'Indented'
$xmlWriter.Indentation = 1
$XmlWriter.IndentChar = "`t"
# write the header
$xmlWriter.WriteStartDocument()
# create root element
$XmlWriter.WriteComment('System Information')
$xmlWriter.WriteStartElement('Data Details')
Foreach ($f in $File)
{
$GetHash = Get-FileHash $f -Algorithm SHA256
$HASH = $GetHash.HASH
$size = $f.Length
# add three pieces of information:
$xmlWriter.WriteElementString('Name',$f)
$xmlWriter.WriteElementString('SHA256',$HASH)
$xmlWriter.WriteElementString('Size',$size)
$xmlWriter.WriteEndElement()
}
$xmlWriter.WriteEndElement()
# finalize the document:
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
My expected XML file is like this
<?xml version="1.0"?>
<!--System Information-->
<Lists>
<Data Details>
<Name>111-B01-A1.sfu</Name>
<SHA256>4afdfefearfarafaa</SHA256>
<Size>10234</Size>
</Data Details>
<Data Details>
<Name>111-B21-A1.sfu</Name>
<SHA256>4afdfefeardsgafaa</SHA256>
<Size>10234</Size>
</Data Details>
</Lists
Anyone can help please thank you