PowerShell script not accepting $ (dollar) sign

PowershellEscaping

Powershell Problem Overview


I am trying to open an SQL data connection using a PowerShell script and my password contains a $ sign:

$cn = new-object system.data.SqlClient.SqlConnection("Data Source=DBNAME;Initial Catalog=Catagory;User ID=User;Password=pass$word;")

When I try to open a connection it says:

> Login failed

Powershell Solutions


Solution 1 - Powershell

Escape it by using backtick (`) as an escape character for the dollar sign ($).

Also, try to enclose the statement in single-quotes instead of the double-quotes you are using now.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMurtaza MandviView Question on Stackoverflow
Solution 1 - PowershellShankar R10NView Answer on Stackoverflow