I'm running a PS script that is loading the SqlServer module and then calling Invoke-SqlCmd. The Invoke-SqlCmd is calling a script with stored procedure.
I originally developed the script using 21.1.18256. Everything is working, but v21.1.18256/Invoke-SqlCmd does not work with -TrustServerCertificate. I found out this option is not available in this version and so decide to upgrade to be able to use this parameter.
I then upgraded to v22.1.1. I tested and found that the Invoke-SqlCmd reacts differently in this version running the same stored procedure. Running the exact same script, the procedure does not work.
I ran it interactively and it see it calling the procedure and shows that it is working. I checked the database and found that no records were inserted.
I have a Try/Catch, Begin/End Tran in the SQL script. I removed the Begin/End Tran and the stored procedure reacted differently. Now it does the inserts as expected, but only partially. In a table that I'm expected 100 records, I'm only getting 25 records.
I've tried v22.0.59 and the results were the same as v22.1.1. When I switch back to v21.1.18256, everything is working correctly and the record counts are as expected. I'm currently switching to native sqlcmd.exe and it is working as expected.
Not sure if anybody have seen this before or am I doing something incorrectly.
I'm on Windows 2019 / SQL Server 2019 / PS v5.1
TrustServerCertificateis relevant to this. Anyway, it might just be as simple as some bad error handling combined withXACT_ABORTbeing on or off depending on version. But hard to say without seeing what you are doing.