Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy-DbaCredential issue when name of credential contains square brackets #9242

Closed
ibaxo opened this issue Feb 14, 2024 · 1 comment
Closed
Labels
bugs life triage required New issue that has not been reviewed by maintainers

Comments

@ibaxo
Copy link
Contributor

ibaxo commented Feb 14, 2024

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Getting an error:
Failed Exception calling "Query" with "1" argument(s): "Exception calling "ExecuteWithResults" with "1" argument(s): "Execute w...

When trying to use Copy-DbaCredential on credentials created by/for replication, which contains square brackets '[', ']' in their name for example on a credential with name like:
[REPL][XXX][XXXX]

image

Steps to Reproduce

1.) Create a credential on MSSQL which does contain square brackets '[', ']' in it's name, for example:
[REPL][MyDomain\TestAccount][ServerName-ReplicationName]
2) Execute Copy-DbaCredential with source as the server containing mentioned credential.

Please confirm that you are running the most recent version of dbatools

2.1.7

Other details or mentions

Problem seems to be laying in Copy-DbaCredential, Line: 220
$destServer.Query("CREATE CREDENTIAL [$sqlcredentialName] WITH IDENTITY = N'$identity', SECRET = N'$password' $cryptoSQL")

There are used square brackets in front and after $sqlcredentialName instead of using proper QUOTENAME function for escaping.

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.20348.2110
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.2110
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2022 (RTM-CU8) (KB5029666) - 16.0.4075.1 (X64)

.NET Framework Version

PSChildName Version


Client 4.8.04161
Full 4.8.04161
Client 4.0.0.0

@ibaxo
Copy link
Contributor Author

ibaxo commented Feb 14, 2024

Created pull request:
#9243

Not sure if it's correct fix, it's just proposed fix, which works for me.

Because:
$decryptedCredentials items already contain a property .Quotename which is escaped correctly by QUOTENAME function.
One possible fix could be to use the value from .Quotename property instead of $credentialName variable

Referenced commit:
https://github.com/dataplat/dbatools/compare/development...ibaxo:issue/9242?expand=1#diff-7768bb5b72caf8c08848cb0a46f4d9e59e17bc1e41fd35800befda1d57863ffb

potatoqualitee pushed a commit that referenced this issue Mar 7, 2024
…name - Issue #9242 (#9243)

Co-authored-by: Ivan Vacho <ivan.vacho@ccs.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs life triage required New issue that has not been reviewed by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants