Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (Get-Content c:temptest.txt).replace('[MYID]', 'MyValue') | Set-Content c:temptest.txt
  2.  
  3. (Get-Content c:temptest.txt) -replace '[MYID]', 'MyValue' | Set-Content c:temptest.txt
  4.  
  5. (Get-Content file.txt) |
  6. Foreach-Object {$_ -replace '[MYID]','MyValue'} |
  7. Out-File file.txt
  8.  
  9. $content = [System.IO.File]::ReadAllText("c:bla.txt").Replace("[MYID]","MyValue")
  10. [System.IO.File]::WriteAllText("c:bla.txt", $content)
  11.  
  12. $path = "C:testFile.txt"
  13. $word = "searchword"
  14. $replacement = "ReplacementText"
  15. $text = get-content $path
  16. $newText = $text -replace $word,$replacement
  17. $newText > $path
  18.  
  19. get-content $pathToFile | % { $_ -replace $stringToReplace, $replaceWith } | set-content $pathToFile
  20.  
  21. try
  22. {
  23. $reader = [System.IO.StreamReader] $pathToFile
  24. $data = $reader.ReadToEnd()
  25. $reader.close()
  26. }
  27. finally
  28. {
  29. if ($reader -ne $null)
  30. {
  31. $reader.dispose()
  32. }
  33. }
  34.  
  35. $data = $data -replace $stringToReplace, $replaceWith
  36.  
  37. try
  38. {
  39. $writer = [System.IO.StreamWriter] $pathToFile
  40. $writer.write($data)
  41. $writer.close()
  42. }
  43. finally
  44. {
  45. if ($writer -ne $null)
  46. {
  47. $writer.dispose()
  48. }
  49. }
  50.  
  51. Get-ChildItem 'C:yourfile*.xml' -Recurse | ForEach {
  52. (Get-Content $_ | ForEach { $_ -replace '[MYID]', 'MyValue' }) |
  53. Set-Content $_
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement