Advertisement
guyrleech

Update text in multiple files via regex

May 22nd, 2020
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## in -replace ( ) are used to define matching groups so $1 is the first match group, eg .*<WindowsTargetPlatformVersion> which we insert back in the replacement string via ${1}. Similarly ${3} for the last match </WindowsTargetPlatformVersion> so we are replacing everything within those two tags in the file
  2.  
  3. Get-ChildItem -Path "*.vcxproj" -file -force -recurse| ForEach-Object { Copy-Item "$($_.FullName)" "$($_.FullName).bak" ; ( Get-Content $_.FullName ) -replace '(.*<WindowsTargetPlatformVersion>)(.*)(</WindowsTargetPlatformVersion>)' , '${1}10.0.18362.0${3}' | Set-Content $_.FullName }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement