Closed wrthmn closed 1 year ago
@wrthmn please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
@microsoft-github-policy-service agree [company="{your company}"]
Options:
- (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
- (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement
@microsoft-github-policy-service agree company="Akvelon"
Motivation:
Set-RsDatabase
script started to result in failure with the following error:After investigation, I discovered that this behavior is a result of the recent update of SQL Strict Connection Encryption, which introduced some changes to the defaults of SQL connection encryption.
Since v22,
Invoke-Sqlcmd
cmdlet from PowerShell SqlServer module has three new parameters:According to the documentation on Invoke-Sqlcmd cmdlet, the default value for
-Encrypt
parameter is nowMandatory
, which seems to be the reason of the connection failure, since currently no value for-Encrypt
parameter is specified forInvoke-Sqlcmd
invocation inSet-RsDatabase
script.Previously the encryption of the connection depended on
-EncryptConnection
switch ofInvoke-Sqlcmd
cmdlet, which was not specified in the script and is considered deprecated since v22 of SqlServer module.So, basically, if the user has the SqlServer module v22 or higher installed, the
Set-RsDatabase
/Set-RsDatabaseCredentials
script uses the recently updated version ofInvoke-Sqlcmd
cmdlet, which makes the connection Mandatory encrypted by default.I consider the ability to specify the newly introduced parameters a required improvment for
Set-RsDatabase
andSet-RsDatabaseCredentials
scripts functionality.Changes proposed in this pull request:
Set-RsDatabase
andSet-RsDatabaseCredentials
scripts according to updatedInvoke-Sqlcmd
parameters:Refactored parameters specification for
Invoke-Sqlcmd
invocation.I also tried to ensure compatibility of the modified scripts with different versions of
Invoke-Sqlcmd
cmdlet, since it is present in SqlServer , PsSqlLegacy and SQLPS modules:Invoke-Sqlcmd
cmdlet from this module, and user will have to specify the recently introduced parameters to prevent the default encryption of the connection (-Encrypt=Optional
and-TrustServerCertificate
is advised);How to test this code:
Set-RsDatabase
/Set-RsDatabaseCredentials
script in different environments (various versions of SqlServer and other modules installed/removed);Has been tested on: