The out put is not getting same replacement of line alignment.. but its not getting same alignment(which it should replace 3 lines. But it going zigzag replacement.. looks ugly, any help
<Hello world=””`’$($Apple)’==’Hero'””>Invoice</battery>
<Sunday>World</Sunday>
<battery>Hello</battery>
`$configFiles = Get-ChildItem . *.csconfigini -rec
foreach ($file in $configFiles)
{
try {
Write-Host "Processing $($file.FullName)"
$content = Get-Content $file.PSPath -Raw -ErrorAction Stop
if ($content -match "(<BatchReleaseType>datacenter</BatchReleaseType>)") {
Write-Host "Match found in $($file.FullName)"
$leadingWhitespace = $matches[1] -replace '<String>Invoice</battery>.*', ''
$replacement = @"
${leadingWhitespace}<Hello world=""`'$($Apple)'=='Hero'"">Invoice</battery>
${leadingWhitespace} <Sunday>World</Sunday>
${leadingWhitespace} <battery>Hello</battery>
"@
$content = $content -replace "<String>Invoice</battery>", $replacement
$content | Set-Content $file.PSPath -ErrorAction Stop
Write-Host "Replacement done for $($file.FullName)"
} else {
Write-Host "No match found in $($file.FullName)"
}
} catch [System.UnauthorizedAccessException] {
Write-Host "Skipping file $($file.PSPath) due to permission issue."
} catch {
Write-Host "Error occurred while processing $($file.PSPath): $_"
}
}
`
New contributor
Kevin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.