$files = Get-ChildItem -Path "e:\Projects\Finlytic\FinlyticFundamentals" -Recurse -Include *.cs -Exclude "Migrations\*" foreach ($file in $files) { $content = Get-Content $file.FullName -Raw # regex for logger # match _logger.LogX("message", args) # The tricky part is we need to match the message string correctly. # $content = [regex]::Replace($content, '(_?logger\.Log(?:Information|Warning|Error))\(\s*(ex\s*,\s*)?("[^"]*")\s*(.*?)\)', { # param($match) # ... # }) # Actually, a simpler way is using a Python script via downloaded Python or just do it in powershell carefully. }