I currently have several files that I'm using powershell with the hopes of creating one output file.
I have a template file with key words in it. I have several files with contents that belong in the middle of the template. And I have my list for what I need to replace.
text file Template:
<pi.category>
<figure id="fig6"><title>TITLEHERE</title>
<graphic boardno="GRAPHBOARDNO"></graphic>
</figure>
<fncgrp>
<fnccode>FGCCODE</fnccode>
<fnctitle>FGCTITLE</fnctitle>
</fncgrp>ADDFILETEXTHERE</pi.category>
Second text file, to be inserted at "ADDFILETEXTHERE" (potentially, it could be anything here):
<pi.item><callout assocfig="fig1" numref="c1"/><qty>8</qty>
<smr maintcode="FZ" recovercode="Z" sourcecode="PA"/><nsn><fsc>5310</fsc>
<niin>00-763-8921</niin></nsn><partno>MS51967-23</partno><cageno>96906</cageno>
<name>NUT,PLAIN,HEXAGON</name><desc></desc></pi.item>
And my powershell script:
$content = [IO.File]::ReadAllText(".\insert.txt")
Get-Content C:\template.xml |
Foreach-Object {$_ -replace "R00000", "R00001"} |
Foreach-Object {$_ -replace "TITLEHERE", "Standard Practices"} |
Foreach-Object {$_ -replace "FGCCODE", "01520"} |
Foreach-Object {$_ -replace "FGCTITLE", "Hydraulic Line Stuff"} |
Foreach-Object {$_ -replace "GRAPHBOARDNO", "AVLBCP0123"} |
Foreach-Object {$_ -replace "ADDFILETEXTHERE", "$content"} |
Set-Content C:\output.xml
I can get all of the replace stuff to work, but I can't get the contents of the insert txt file to replace the "addfiletexthere".
How can I replace a keyword with the contents of an existing text file??