theabraxas / Project-Neith

Project Neith is intended to provide an extensible and modular dashboard which conveys important information concisely and enables actions on monitored systems.
https://abraxas.io
GNU General Public License v3.0
22 stars 2 forks source link

Parameterized Queries? #14

Open theabraxas opened 5 years ago

theabraxas commented 5 years ago

Getting some errors like the following when imported data as variables include single quotes or similar characters:

Invoke-Sqlcmd : Incorrect syntax near 'Neil'.
Unclosed quotation mark after the character string ')
'. 
 Msg 102, Level 15, State 1, Procedure , Line 2.
At line:15 char:9
+         Invoke-Sqlcmd -Query $Query
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
    + FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

I've heard Invoke-Sqlcmd2 might have a solution to this, this might be a better way forward

gallman commented 5 years ago

I believe I have an old example of using parameterized queries with this cmdlet. Please remind me this week unless you figure it out before.

theabraxas commented 5 years ago

Sweet, thanks!

On Sun, Feb 3, 2019 at 10:05 PM gallman notifications@github.com wrote:

I believe I have an old example of using parameterized queries with this cmdlet. Please remind me this week unless you figure it out before.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theabraxas/UltimateDashboard/issues/14#issuecomment-460140313, or mute the thread https://github.com/notifications/unsubscribe-auth/AF3MvAvsIlEZrWwBoBWcsWMbWm5HoFWDks5vJ825gaJpZM4agjmo .

gallman commented 5 years ago

I haven’t checked the latest version of the SqlServer module but the dbaTools module supports parameterized queries via their Invoke-DbaSqlQuery function.