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 fails to convert string to sql query. #2

Closed dotps1 closed 7 years ago

dotps1 commented 7 years ago

just trying to use the Invoke-MySqlQuery and it doesn't like the string for the query:

Invoke-MySqlQuery -SqlQuery 'SELECT * FROM v_computers' -Credential $credentials -Database MyDB -Server MyServer

Error:

Invoke-MySqlQuery : Cannot bind parameter 'SqlQuery'. Cannot convert the "SELECT * FROM v_computers" value of type "System.String" to type "InvokeQuery.SqlQuery".
At line:1 char:29
+ Invoke-MySqlQuery -SqlQuery 'SELECT * FROM v_computers' -Credential $ ...
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-MySqlQuery], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,InvokeQuery.InvokeMySqlQuer
ctigeek commented 7 years ago

Sorry for the delay in answering. There are two ways to pass in queries, and I admit it's a little confusing. To simply pass in Sql text, use the -Sql parameter:

Invoke-MySqlQuery -Sql 'SELECT * FROM v_computers' -Credential $credentials -Database MyDB -Server MyServer

The SqlQuery parameter is actually an object you have to build that consists of the Sql text, Sql parameters, and other information. It's used for piping in multiple CUDs in a single transaction. For more information on the SqlQuery parameter see the doc here: https://github.com/ctigeek/InvokeQueryPowershellModule#sqlquery-parameter

Let me know if you have any other problems! Steve

dotps1 commented 7 years ago

right on, thanks for the explination, i already built my solution using @RamblingCookieMonster 's Invoke-MySqlQuery script.