How can I set -TrustServerCertificate as a default for Invoke-SQLCmd?

0
16
Asked By TechieTurtle42 On

I'm looking for a way to make the "-TrustServerCertificate" parameter the default behavior when using the Invoke-SQLCmd cmdlet in PowerShell. I don't want to have to type it out every single time I run the command. In Linux, I could easily create an alias for this, but I'm wondering if there's a similar solution for Windows 11 using PowerShell Core v7.5.4. Any suggestions?

3 Answers

Answered By ScriptyWiz456 On

You can set default parameter values using $PSDefaultParameterValues in your PowerShell profile. Just add this line: `$PSDefaultParameterValues['Invoke-SqlCmd:TrustServerCertificate'] = $true`. This way, it'll automatically apply the -TrustServerCertificate option every time you use Invoke-SqlCmd.

Answered By PromptPal123 On

Consider using dbatools! It's pretty slick and you can set the default once in your profile so you don’t have to repeat it each time. Check out their documentation for setting up an insecure connection.

Answered By CodeCrafty789 On

There are really two paths you can take. You can create an alias like you mentioned, but more effectively, you should use $PSDefaultParameterValues. Just add this to your $PROFILE file to ensure that -TrustServerCertificate is always set when you call Invoke-SqlCmd.

AliasExpert101 -

Just a heads up, PowerShell aliases work a bit differently than Bash aliases. They only handle the command names, not parameters. For something similar to Bash aliases, consider creating a wrapper function instead.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.