Hi All.
I have a script below, the purpose of the script is as follows.
Pass a file to the script containing a list of SQL instances.
Pass an array of files to the script.
Run each and every script on all the SQL instances defined in the file from step 1
param(
[string[]] $file_list,
[string] $in_sql_server_instances_file_path
)if (!(test-path $in_sql_server_instances_file_path)){ write-output "The file does not exist" return 1 } $file_server_list = get-content -path $in_sql_server_instances_file_path workflow execute-parallel { param( [string []] $sql_instances, [string []] $files_to_execute ) foreach -parallel -throttlelimit 8 ($sql_instance in $sql_instances){ inlineScript{ $wf_sql_instance = $using:sql_instance $wf_files_to_execute = $using:files_to_execute foreach ($file_to_execute in $wf_files_to_execute){ Invoke-Sqlcmd -ServerInstance "$wf_sql_instance" -Database "tempdb" -InputFile $file_to_execute } } } } execute-parallel -sql_instances $file_server_list -files_to_execute $file_list
To execute the script.
.\execute.ps1 -file_list 'C:\Scripts\a.sql','C:\Scripts\b.sql' -in_sql_server_instances_file_path 'C:\Scripts\sql_servers.txt'
I am trying to achieve the following.
If a file fails, stop execution on the server but move onto the next server in the loop.
Handle error control
Deploy the files in the order specified in the -file_list array parameter.
4.How can i be certain that a.sql will always run before b.sql ?
The file sql_servers.txt contains a list of SQL instances.