ctigeek / InvokeQueryPowershellModule

A Powershell module of Cmdlets for querying most types of databases.
https://www.powershellgallery.com/packages/InvokeQuery
MIT License
58 stars 10 forks source link

[invoke-mysqlquery] password issues (can't connect due to semicolons or backticks in password #15

Open mbourgon opened 5 years ago

mbourgon commented 5 years ago

Howdy. I've run into a problem on a MySQL server I'd like to use invoke-mysqlquery for. Using a login that involves a semicolon or backtick appears to cause errors. On the backtick I get a simple 'access denied', though I can work around it by adding 1 extra backtick (which probably means you'd need 1 extra backtick per actual backtick). On the one with multiple special characters, I get the below error, probably related to the semicolon in the password, but could be the equals sign.

I'm unsure how the connection string creator handles it, but I would expect you could put the password in double quotes and have it work.

Thanks in advance!

$secpasswd = ConvertTo-SecureString "g@=_;adbgw$yuv&" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("abcdefgh", $secpasswd)
$server = "localhost"
$table = "``TABLES``"
$query = "select count(*) from $table";
$result = (Invoke-MySqlQuery -sql $query -Database $db -Credential $mycreds -Verbose -Server $server )

I get the following error. (note that it shows the partial password, which shows that it's due to it misinterpreting the semicolon):

VERBOSE: Using the following connection string: Data Source=localhost;Initial Catalog=INFORMATION_SCHEMA;User ID=abcdefgh;Password=xxxxxxxxxx;adbgw&;
VERBOSE: Opening connection.
Invoke-MySqlQuery : Format of the initialization string does not conform to specification starting at index 95.
At line:14 char:12
+ $result = (Invoke-MySqlQuery -sql $query -Database $db -Credential $mycreds -Ver ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-MySqlQuery], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,InvokeQuery.InvokeMySqlQuery