Invoke-SqlCmd2 icon indicating copy to clipboard operation
Invoke-SqlCmd2 copied to clipboard

Trust Server Certificate Switch

Open mattmcnabb opened this issue 8 years ago • 4 comments

I've been using a modified version of Invoke-SqlCmd2 with an added switch -TrustServerCertificate for cases where the cert returned is not in the local trusted store. Generally I've used this for testing with a self-signed cert. Do you see any value in adding this to Invoke-SqlCmd2?

$FormatValues = $SQLInstance,$Database,$Credential.UserName,$Credential.GetNetworkCredential().Password,$ConnectionTimeout,$Encrypt,$TrustServerCertificate
$ConnectionString = "Server={0};Database={1};User ID={2};Password=`"{3}`";Trusted_Connection=False;Connect Timeout={4};Encrypt={5};TrustServerCertificate={6}" -f $FormatValues

mattmcnabb avatar Feb 23 '17 12:02 mattmcnabb

@mattmcnabb I have basic support for adding this parameter to the connection string in my branch https://github.com/alevyinroc/Invoke-SqlCmd2/tree/Fix-009

When my previous PR is approved & merged into master, I can do a PR to get that change merged in as well. I don't have a good way to test this at the moment though.

@RamblingCookieMonster can you please assign to me?

alevyinroc avatar Nov 16 '17 04:11 alevyinroc

Howdy, @alevyinroc , did this ever get rolled in? I'm looking at the current version, and I don't see the trustservercertificate code in there, though obviously it's in yours. Just wondering if I need to just use the version in Fix-009 instead. Thanks!

mbourgon avatar May 16 '23 20:05 mbourgon

@mbourgon It has not. I honestly had forgotten about this, it's been over 5 years now. I suspect most if not all of this module's functionality has been consumed into dbatools's Invoke-DbaQuery, making this obsolete.

alevyinroc avatar May 17 '23 01:05 alevyinroc

Not terribly surprised, but wanted to make sure.

Honestly, we have servers that get the bare minimum done to them. Patched, migrated when the OS falls out of extended support, and that’s it. This code has been a lifesaver over the years because it has zero dependencies on anything else. So I’m still able to use it on pretty much any server in our environment without any installs or Change Requests or restarts. I’ll use this one, then. Thanks!

mbourgon avatar May 17 '23 01:05 mbourgon