sqlpowershellinvoke-sqlcmd

Is there any option to accept server certificate in powershell Invoke-Sqlcmd?


Steps I have done:

Invoke-Sqlcmd -ServerInstance "SERVER\SQL" -query "USE databsename SELECT GETDATE();" -Username "username" -Password "strongpassword"

ERROR:

Invoke-Sqlcmd : Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=8; handshake=14993;

Same command work absolutely fine when run from my local machine or from other server.

Is there any step to make the cert trusted on new installed windows server please?


Solution

  • Because it is new system, so all the settings microsoft setting up automatic without user interaction.

    The issue was with the certificate, but not strictly with certificate it self, but with the system time zone. If you are in the same situation like me, make sure your time zone and time are correct.