I've got a CSV file with both the data I want to replace in an XML and the data I want to replace it with; Header A is what I want to replace; Header B is what I want to replace it with:
HeaderA, HeaderB
Data A1, Data B1
Data A2, Data B2
Data A3, Data B3
I'm trying to do this with power-shell using this solution provided here:
Replace multiple Strings with Data from CSV
Modifying the solution provided there to:
$CSVData = Import-Csv .\MyCSV.csv
$xml = Get-Content -Raw .\MyXML.xml
foreach ($row in $CSVData) {
$xml.Replace($row.HeaderA, $row.HeaderB) |
Out-File ".\MyXMLCopy.xml"
}
I only need the XML as one file; as opposed to what was needed there.
EDIT: What about combining this operation with a multiple file replace? As discussed: Replace multiple strings in a file using powershell So far I've been attempting this:
$ReplaceList = Import-Csv ".MyCSV.csv"
$ChangeList = Get-Childitem ".\*Map.xml" | ForEach-Object FullName
foreach ($file in $ChangeList) {
foreach ($row in $ReplaceList) {
Get-Content $file |
ForEach-Object {$_ -replace "$($row.HeaderA)", "$($row.HeaderB)"}
| Set-Content $_.FullName
}}
Failing at Set-Content