I'll start by recognizing that I'm Powershell (and coding) noob. I came across several scenarios, but I do not pretend to anything, even approaching competence. I hope some more experienced people can put me on the right track.
I am trying to pull specific element data from several XML files that will be used to populate another XML file. The files from which I extract the data are invoices, and I would like to get the account number and time stamp and drop these values ββinto the manifest. The structure of the manifest is as follows
<?xml version="1.0" encoding="utf-8"?>
<Manifest>
<Invoice>
<InvoiceID></InvoiceID>
<Timestamp></Timestamp>
</Invoice>
</Manifest>
The XML I am pulling from is in a subdirectory of the directory in which the manifest will be saved. For simplicity, the element names in the invoices are identical to the corresponding manifest elements. The folder structure for the manifest is " C:\Projects\Powershell\Manifest\Manifest.xml", and for invoices it is " C:\Projects\Powershell\Manifest\Invoices\*.xml".
"InvoiceID" "Timestamp" XML "\Invoices". ; , . (, , XML - "\Invoices", : <Invoice>, InvoiceID Timestamp, , , , .)
:
$files = Get-ChildItem "C:\Projects\Powershell\Manifest\Invoices\*.xml"
$xmlData = @"
<Invoice>
<InvoiceId>$InvID</InvoiceId>
<Timestamp>$Timestamp</Timestamp>
</Invoice>
"@
$Manifest = "C:\Projects\Powershell\Manifest\Manifest.xml"
ForEach ($file in $files) {
$xmldoc = [xml](Get-Content $file)
$InvID = $xmldoc.Manifest.Invoice.InvoiceID
$Timestamp = $xmldoc.Manifest.Invoice.Timestamp
ForEach ($xml in $xmldoc)
{
Add-Content $Manifest $xmlData
}}
, .
, , , , , , , . /?