execute all sql scripts stored in certain folder and if someone fails in between then loop should exit and record error
#run sql scripts/sps from folder C:\MyTSQLScripts and if any error ocour then it this loop will stop and error record in output file
Get-ChildItem -Path "C:\MyTSQLScripts" -Filter "*.sql" | % {invoke-sqlcmd -InputFile $_.FullName}
foreach ($f in Get-ChildItem -path "C:\MyTSQLScripts\" -Filter *.sql | sort-object){
$out = "C:\MyTSQLScripts\" + $f.name.split(".")[0] + ".txt" ;
invoke-sqlcmd –ServerInstance myServer -Database DBname -InputFile $f.fullname | format-table | out-file -filePath $out
}foreach ($f in Get-ChildItem -path "C:\MyTSQLScripts\" -Filter *.sql | sort-object -desc )
{
$out = "C:\MyTSQLScripts\" + $f.name.split(".")[0] + ".txt" ;
invoke-sqlcmd -InputFile $f.fullname | format-table | out-file -filePath $out
}
above script gives error: The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path w
as included, verify that the path is correct and try again.