Я пытаюсь заменить URL внутри XML.например,
http://sample.com/v2/some/action
до
http://sample-v2.com/v2/some/action
Пример XML:
<someroot>
<serice>
<action url="http://sample.com/v2/some/action" />
</service>
</someroot>
Когда я запускаю этот скрипт:
$path = "..."
$line = "http://sample.com/v2/some/action"
$replacement = "http://sample-v2.com/v2/some/action"
(Get-Content $path) | Foreach-Object {
$_ -replace $line, $replacement
} | Out-File ($path + ".replaced.xml")
itне работаетЧто я делаю не так?
ОБНОВЛЕНИЕ:
Фактический код:
foreach ($line in $inputLines) {
$replacement = $line.Replace("sample.test", "sample-" + $suffix + ".test")
Write-Host ("Current input line:", $line) -ForegroundColor Yellow
Write-Host ("Will be replaced with:", $replacement) -ForegroundColor Yellow
(Get-Content $path) | Foreach-Object {
$_.Replace($line, $replacement)
} | Out-File ($path + ".replaced.xml")
}