microsoft / ReportingServicesTools

Reporting Services Powershell Tools
MIT License
458 stars 213 forks source link

Updated Set-RsDatabase and Set-RsDatabaseCredentials scripts to support new parameters of Invoke-Sqlcmd. #401

Closed wrthmn closed 1 year ago

wrthmn commented 1 year ago

Motivation:

Set-RsDatabase script started to result in failure with the following error:

Executing database creation script... Failed! Invoke-Sqlcmd : A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

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 now Mandatory, which seems to be the reason of the connection failure, since currently no value for -Encrypt parameter is specified for Invoke-Sqlcmd invocation in Set-RsDatabase script.

Previously the encryption of the connection depended on -EncryptConnection switch of Invoke-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 of Invoke-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 and Set-RsDatabaseCredentials scripts functionality.

Changes proposed in this pull request:

How to test this code:

Has been tested on:

wrthmn commented 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"