I would like to use power shell to loop all subfolders and run all the files in it. But, if my root contain 3 subfolders, I would like to loop and list it accordingly to the sequence where : Subfolder C , Subfolder B and Subfoder A so that the file execution will run according to the sequence ( C–>B–>A) .
Below is my coding, Please advise me on this. Thank you so much.
Get-ChildItem -path "C:\Root\subfolders\" -recurse -Filter *.sql |
foreach-object -process { $.FullName }| ForEach-Object { sqlcmd -i $ }
You could sort the list of
.sqlfiles to run by the name of their parent folder before executing them using the Sort-Object cmdlet: