Friday, 18 November 2011

Admin: Execute Folder of Scripts

Here's a simple powershell script to loop through a directory and execute the sql files contained within:

ADD-pssnapin SqlServerCmdletSnapin100

$ServerName
= "MySERVER" 

$Db = "MyDB" 
$scriptDir = "c:\FileDir\"

$files
= gci $scriptDir* -include *.sql

foreach
($file IN $files

{
Invoke
-Sqlcmd -ServerInstance $ServerName -DATABASE $Db -InputFile $File
}

No comments:

Post a comment

/* add this crazy stuff in so i can use syntax highlighter