Quick Powershell and SQL Server tip

Today I had to create a quick copy of a database for some integration testing purposes. In the process, I learnt two things:

1. How to replace text in a bunch of files with Powershell:

dir Create* | % { $file=$_; (Get-Content $file) | % { $_ -replace '\[RealDb\]', '[My_Db_Copy]' } | Set-Content $file }

2. How to execute a bunch of files against a SQL server:

dir Create* | % { sqlcmd -S MY_DATABASE_SERVER -i $_ }

No rocket science, but very, very helpful to me. And maybe to someone else?

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s