I need to write up a script in PowerShell that will search through a folder, find ONLY HTML files, and replace a certain line of markup that I specify with new markup.
Here is what I have so far:
$filePath = 'C:\Users\bettiom\Desktop\schools\alex\Academics'
$processFiles = Get-ChildItem -Exclude *.bak -Filter *.htm -Recurse -Path $filePath
$query = '<html>'
$replace = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
foreach ( $file in $processFiles ) {
$file | Copy-Item -Destination "$file.bak"
$arrayData = Get-Content $file
for ($i=0; $i -lt $arrayData.Count; $i++) {
if ( $arrayData[$i] -match $query ) {
$arrayData[$i+1] = $arrayData[$i+1].Replace($query,$replace)
} else { }
}
$arrayData | Out-File $file -Force
}
Everything seems to work up until the foreach loop, it then just doesn't execute pass that line.
Any help given will be much appreciated.
Thanks in Advance.