top of page

SQL PowerShell to the rescue

  • Repost - originally posted 24-08-2012
  • Oct 11, 2017
  • 1 min read

As part of on going development I was required to run all the database scripts for a new database. This was just less than 300 scripts and it was getting laborious doing it manually. So I delved into the world of SQL PowerShell and found a handy script to automate the running of these scripts.

Now the rebuild of the entire database is automated by one simple script.

Sample code: foreach ($f in Get-ChildItem -path "C:\Scripts\" -Filter *.sql | sort-object) { invoke-sqlcmd –ServerInstance "XXX" -Database "YYY" -InputFile $f.fullname -SuppressProviderContextWarning }


 
 
 

Recent Posts

See All
Cardinality estimator

Recently I was asked by a software vendor to review a particular query that ran in under a second on a SQL Server 2014 installation at a...

 
 
 
Index fragmentation

A law firm client, occasionally has issues with their legal software, that is provided by the global leader in this field. The response...

 
 
 
Deleting large amounts of data

I had a client call me about wanting to delete a large amount of data from their database. They knew what tables they wanted to delete...

 
 
 

Comments


bottom of page