February 4, 2018 at 9:29 am
Hello -
I am newbie to powershell. I am able to execute all the .SQL files from directory on to the server serially using below command. But, we want to execute all these files in parallel. CAn someone please help?
My code for serial execution -
$PSScriptRoot = 'Y:\ODS Consolidation\ODSRefresh\test\'
$ServerName = $env:COMPUTERNAME
#Invoke-Sqlcmd -InputFile $DBListScript -ServerInstance $ServerName
foreach ($f in Get-ChildItem -path $PSScriptRoot -Filter *.sql | sort-object -desc )
{
invoke-sqlcmd -InputFile $f.fullname -ServerInstance $ServerName
}
February 4, 2018 at 2:12 pm
Please find answer below if anyone is looking for it -
foreach ($f in Get-ChildItem -path $PSScriptRoot -Filter *.sql | sort-object -desc) { Start-Job -ScriptBlock { invoke-sqlcmd -InputFile $args[0].fullname -ServerInstance $args[1] } -ArgumentList $f, $ServerName}
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy