You can simply open the “Windows powerShell ISE”.
paste the below script and update the variables as per your
folder and SQL details. You need to update ServerName,
DatabaseName,"UserName","Password" and Folder Path.
#Provide SQLServerName
$ServerName ="ServerName"
#Provide SQLServerName
$ServerName ="ServerName"
#Provide Database Name
$DatabaseName ="DatabaseName"
#Provide Login UserName
$UserName = "sa"
#Provide Login Password
$Password = "Password"
#Scripts Folder Path
$FolderPath ="E:\Workspace\SqlScripts \"
#Loop through the .sql files and run them
foreach ($filename in get-childitem -path $FolderPath -recurse -file -filter "*.sql" |
sort-object)
{
invoke-sqlcmd –ServerInstance $ServerName -Database $DatabaseName -Username $UserName -Password $Password -InputFile $filename.fullname
#Print file name which is executed
$filename
}
And press run button it will execute all your scripts.