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
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.
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.
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.

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.