Created
November 11, 2015 17:28
-
-
Save MikeFal/b98ed2beb324d553b9c2 to your computer and use it in GitHub Desktop.
Running a SQL Script in parallel
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
#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