Created
March 20, 2020 11:27
-
-
Save paschott/50d6ba81af5462797973e7c7ef9abbf2 to your computer and use it in GitHub Desktop.
This file contains 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
Import-Module dbatools | |
$scripts = get-childitem "C:\ScriptsToRun\" -Filter *.sql | sort-object Name | |
$servers = "servername" | |
$database = "databasename" | |
foreach ($script in $scripts) { | |
$OutputFile = $script.directoryname + "\" + $script.basename + ".txt" | |
Write-Host $OutputFile | |
Invoke-DbaQuery -SqlInstance $servers -File $script.FullName -Database $database -MessagesToOutput | Out-File -FilePath $OutputFile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment