Skip to content

Instantly share code, notes, and snippets.

@paschott
Created March 20, 2020 11:27
Show Gist options
  • Save paschott/50d6ba81af5462797973e7c7ef9abbf2 to your computer and use it in GitHub Desktop.
Save paschott/50d6ba81af5462797973e7c7ef9abbf2 to your computer and use it in GitHub Desktop.
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