r/PowerShell • u/chuckh1958 • Nov 25 '25
Invoke-SQLCMd make -TrustServerCertificate the default behavior
With the Invoke-SQLCmd cmdlet, I'd like to make the "-TrustServerCertificate" parameter a default. Is that possible? IOW I don't want to have to specify it every time I invoke the cmdlet.
In Linux I could set up an alias something like this:
alias Invoke-SQLcmd="Invoke-SQLcmd -TrustServerCertificate".
Can something like that be done in Windows 11 with Powershell Core v7.5.4?
4
Upvotes
12
u/jborean93 Nov 25 '25
Unless it came with a module specific way to set this in their own custom way you can use $PSDefaultParameterValues. Set this in your profile or script to ensure the
-TrustServerCertificateis set by default forInvoke-SqlCmd1
u/dodexahedron Nov 27 '25
XY problem.
Is putting a valid cert on the server for some reason not possible?
If not, trust that specific cert. Don't make this the default for sqlcmd, or else it applies to ALL servers. That makes it almost pointless to be bothering with TLS if security is remotely a concern, because you have no guarantee you are not being MITMd.
3
u/lan-shark Nov 25 '25
There are two simple options for this. One is an alias like you mentioned, but you can also use $PSDefaultParameterValues, I think adding this to your
$PROFILEshould work:3
u/ipreferanothername Nov 25 '25
i think if you move to using dbatools, which is slick, you can set it once per profile and not have to do it every time.
https://dbatools.io/Set-DbatoolsInsecureConnection/
but you are suffering the same problem my org is - the dbas have no idea that the certs are now required and just check a skip-this-shit box or pass a parameter like this every time they do something.
1
u/bobthewonderdog Nov 25 '25
Psdefaultparametervalues is likely to be the best solution here. https://devblogs.microsoft.com/powershell-community/how-to-use-psdefaultparametervalues/
-1
u/Ok_Mathematician6075 Nov 26 '25
If you are asking us that is telling.