title: PowerShell command to replace a chunk of text in a file
body: <p>I am trying to replace a chunk of text in a file using PowerShell. For instance, I have a .sql file and I know the exact chunk of an SQL script that needs to be replaced in that particular file. After reading through some of the PowerShell replace examples it looks like PowerShell returns the content of the file in an array (each line representing one entry in the array).</p>
  
  <p><strong>For example:</strong></p>
  
  <pre><code>GO
  :on error exit
  GO
  IF (DB_ID(N'$(DatabaseName)') IS NOT NULL)
  BEGIN
      ALTER DATABASE [$(DatabaseName)]
      SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
      DROP DATABASE [$(DatabaseName)];
  END
  
  GO
  PRINT N'Creating $(DatabaseName)...'
  GO
  CREATE DATABASE [$(DatabaseName)] COLLATE SQL_Latin1_General_CP1_CI_AS
  GO
  
  USE [$(DatabaseName)]
  .......
  .........
  ..... MORE SQL SCRIPT
  </code></pre>
  
  <p>I want to replace the text till USE [$(DatabaseName)] in the above file.</p>