Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Help needed doing a find/replace on a group of text files

$
0
0

Adam and Mathieu,

As far as I know the -match and -replace operators in PowerShell are case-insensitive. Below example works for me using a different set of test files of course.

$TextFiles = @('D:\MDTProduction\Control\Bootstrap.ini',
			'D:\MDTProduction\Control\Customsettings.ini',
			'D:\MDTBuildLab\Control\Bootstrap.ini',
			'D:\MDTBuildLab\Control\Customsettings.ini',
			'D:\MDTBuildLab\Scripts\Realocate.cmd'
		)
 
foreach ($FilePath in $TextFiles) {
  $Content = Get-Content $FilePath
 
  Write-Verbose "Searching for string in $FilePath"
  if ($Content -match 'mdt-01') {
    Write-Verbose "Found mdt-01 match in $FilePath"
    $Content = $Content -replace 'mdt-01', 'replacethis'
 
    Set-Content -Path $FilePath -Value $Content
  }
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles