I’ve got a workflow that I intended to run a script on multiple servers, and in multiple databases on each of them, at the same time.
What I’ve found is that it runs on one server at a time and only in 2 databases at a time.
I’m looking for advice, suggestions, to get this working as I intended, if that’s possible.
#requires -version 3.0 cls Import-Module sqlps -DisableNameChecking; set-location c: WorkFlow Run-CarrierInfo { param( [Parameter(Mandatory=$true)] [string[]]$Servers, [Parameter(Mandatory=$true)] [string]$FilePath ) foreach -parallel ($Server in $Servers) { foreach -parallel ($database in Invoke-SqlCmd -ServerInstance $Server -Query "SELECT name FROM sys.databases WHERE database_id > 4 AND name NOT LIKE 'reporting_%' AND name NOT IN ('db1','db2','db3','db4')") { Write-Output $($database.name) $Results = Invoke-SqlCmd -ServerInstance $server -Database $($database.name) -InputFile $FilePath -querytimeout ([int]::MaxValue) Write-Output $Results } } } $StopWatch = [system.diagnostics.stopwatch]::StartNew() $carrierInfoquery = "X:\Scripts\CarrierInfo\carrierInfo.sql" $Servers = "srv1","srv2" $carrierInfoReport = "X:\Reports\CarrierInfo\$((GET-DATE).ToString("yyyyMMdd"))_carrierInfo.csv" $r = Run-CarrierInfo -Servers $servers -FilePath $carrierInfoquery | Select -Property SERVER_NAME,ENVIRONMENT,CONTROL_ID,PROCESS_ID,DESCRIPTION,VENDOR,OCCURANCE,EXPORT_FILENAME,EXPORT_NAME,IS_BUILDER_FILE $r | Export-Csv $carrierInfoReport -NoTypeInformation -Append $StopWatch.Stop() Write-Output "Elspsed minutes for v1 are: $($StopWatch.Elapsed.TotalMinutes)"