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

Time:02-02

Steps I have done:

  • installed new widows server 2022
  • enables Set-ExecutionPolicy
  • installed sql module for powerhell
  • run command:

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?

CodePudding user response:

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.

  • Related