Skip to content

Instantly share code, notes, and snippets.

@MikeFal
Created November 11, 2015 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeFal/b98ed2beb324d553b9c2 to your computer and use it in GitHub Desktop.
Save MikeFal/b98ed2beb324d553b9c2 to your computer and use it in GitHub Desktop.
Running a SQL Script in parallel
#ServerList
$servers = @('PICARD','RIKER','KIRK','SPOCK')
#Using a Workflow
workflow SQLScript{
foreach -Parallel ($server in $servers){
Invoke-Sqlcmd -ServerInstance $server -InputFile C:\TEMP\TestScript.sql
}
}
#Using Background jobs
$servers | ForEach-Object {Start-Job -ScriptBlock {Invoke-Sqlcmd -ServerInstance $_ -InputFile C:\TEMP\TestScript.sql}}
Get-Job | Wait-Job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment