Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.