title: Find replace using PowerShell get-content
body: <p>I am attempting to mask SSN numbers with Random SSNs in a large text file. The file is 400M  or .4 gigs.</p>
  
  <p>There are 17,000 instances of SSNs that i want to find and replace.</p>
  
  <p>Here is an example of the powershell script I am using.</p>
  
  <pre><code>(get-content C:\TrainingFile\TrainingFile.txt) | foreach-object {$_ -replace "123-45-6789", "666-66-6666"} | set-content C:\TrainingFile\TrainingFile.txt
  </code></pre>
  
  <p>My problem is that that i have 17,000 lines of this code to that I have in a .ps1 file. The ps1 file looks similar to </p>
  
  <pre><code>(get-content C:\TrainingFile\TrainingFile.txt) | foreach-object {$_ -replace "123-45-6789", "666-66-6666"} | set-content C:\TrainingFile\TrainingFile.txt
  
  (get-content C:\TrainingFile\TrainingFile.txt) | foreach-object {$_ -replace "122-45-6789", "666-66-6668"} | set-content C:\TrainingFile\TrainingFile.txt
  
  (get-content C:\TrainingFile\TrainingFile.txt) | foreach-object {$_ -replace "223-45-6789", "666-66-6667"} | set-content C:\TrainingFile\TrainingFile.txt
  
  (get-content C:\TrainingFile\TrainingFile.txt) | foreach-object {$_ -replace "123-44-6789", "666-66-6669"} | set-content C:\TrainingFile\TrainingFile.txt
  </code></pre>
  
  <p>For 17,000 powershell commands in the .ps1 file. One command per line.</p>
  
  <p>I did a test on just one command and it took about 15 secoonds to execute.  Doing the math, 170000 X 15 seconds comes out to about 3 days to run my .ps1 script of 17,000 commands.</p>
  
  <p>Is there a faster way to do this?</p>