0

I am trying to run a SQL query in my powershell script. Unfortunately some of the tables in the database contain $'s. in this case one of the tables is

ServiceManager.dbo.MT_System$WorkItem$Incident

without any thing changed the table in the SQL Query becomes

ServiceManager.dbo.MT_System

If i use the standard escape character of ' it then becomes

ServiceManager.dbo.MT_System''

If i add another $ it becomes

ServiceManager.dbo.MT_System'}WorkItem'}Incident

I tried surrounding the $ with qoutes which results in

ServiceManager.dbo.MT_System'$'WorkItem'$'Incident

any help would be apreciated

Robyn H
  • 31
  • 1
  • 5
  • Take a look at this thread https://stackoverflow.com/questions/21911112/escaping-strings-containing-single-quotes-in-powershell-ready-for-sql-query and parameterized queries https://stackoverflow.com/questions/4712037/what-is-parameterized-query – alexherm Jul 19 '19 at 22:29
  • 1
    just figured it out i was using ' instead of ` – Robyn H Jul 19 '19 at 22:46
  • @RobynH Feel free to post a self-answer! – Mathias R. Jessen Jul 20 '19 at 15:06

1 Answers1

0

These $ characters can be properly escaped in PowerShell by using the backtick (`) character, such as: ServiceManager.dbo.MT_System`$WorkItem`$Incident.

Cale Vernon
  • 146
  • 2