Replace a changing string in a text file

Hi,

I have script, which fetches a text file (which is a script of a database) into a variable.  Here is a portion of that script:
$DBScriptFile = $Path[0] + $dbname + '\01-DB-' + $dbname + '-' + $Date + '.sql'
$string = Get-Content $DBScriptFile

Inside the file I have strings like:
SIZE = 76288MB
FILEGROWTH = 512MB

I need to replace them with:
SIZE = 1024KB
FILEGROWTH = 1024KB

The problem is, those numbers may be different, e.g.:
SIZE = 10000KB
FILEGROWTH = 2048KB

So I need to replace everything which looks like:
SIZE = XYZB
FILEGROWTH = XYZB
with:
SIZE = 1024KB
FILEGROWTH = 1024KB

Any ideas?

Thanks

Parents
No Data
Reply
  • And not only that, the replacement puts a closing bracket at the end of each line, e.g.:

    USE [master])

    IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'MyDB'))

    BEGIN)

    CREATE DATABASE [MyDB] ON  PRIMARY )

     

    FILEGROUP [MyDB_201212] )

     

    ALTER DATABASE [MyDB] ADD FILEGROUP [MyDB_201301])

    ALTER DATABASE [MyDB] SET COMPATIBILITY_LEVEL = 100)

    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')))

    begin)

    EXEC [MyDB].[dbo].[sp_fulltext_database] @action = 'enable')

    end)

    ALTER DATABASE [MyDB] SET ANSI_NULL_DEFAULT ON )

Children
No Data