Created
August 5, 2020 18:15
-
-
Save djhojd/6ea64529c11e72abfdb67045439b6030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MachineName = $env:computername | |
$InstanceName = "SQLEXPRESS" | |
$ServerInstance = "$MachineName\$InstanceName" | |
Get-SqlInstance -ServerInstance $ServerInstance | |
# Provide SQLServerName | |
$SQLServer = "MySQLSErver\InstanceName" | |
# Provide Database Name | |
$DatabaseName = "my-db-name" | |
# Scripts Folder Path | |
$FolderPath = "c:\sql-files\" | |
# Loop through the .sql files and run them | |
foreach ($filename in get-childitem -path $FolderPath -filter "*.sql") | |
{ | |
invoke-sqlcmd -ServerInstance $ServerInstance -Database $DatabaseName -InputFile $filename.fullname | |
# Print file name which is executed | |
$filename | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment