Hi I have a requirement to connect to sql server and do various operations currently doing it through start-job but we find it very inefficient. Someone pointed to Runspace and this link.
http://powertoe.wordpress.com/2012/05/03/foreach-parallel/
But in my script i have something like this.
It works fine if i pass only one variable to function ForEach-Parallel like this.
$SQLServers= Get-Content "L:\cfg\tst2.cfg"
$SQLServers |ForEach-Parallel -MaxThreads 100{
# Start MAIN #
...declarations..
then
try {
$var=$_
connect to sql server --Then do some processing
}
catch
{
$Error[0]
}
}#End
But If i have something like this it throws an error saying cannot index into a null array , any way to fix it ? I might have to pass multiple parameters.
$SQLServers= Get-Content "L:\cfg\tst2.cfg"
$Database ="DBADB"
$email = "dba@testemail.com"
$Parms =@()
$Parms = @($SQLServers,$Database,$email)
$Parms |ForEach-Parallel -MaxThreads 100{
# Start MAIN #
...declarations..
try {
$var1=$parms[0]
$var2=$parms[1]
$var3=$parms[2]
---Then do some processing
}
catch
{
$Error[0]
}
}#End
I need to pass various inputs to my script then call the ForEach-Parallel function, any way around this?
Thanks