Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell script not accepting $ (dollar) sign

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

like image 401
Murtaza Mandvi Avatar asked Oct 23 '09 18:10

Murtaza Mandvi


People also ask

How do I use the dollar sign in PowerShell?

Working with variables The default value of all variables is $null . To get a list of all the variables in your PowerShell session, type Get-Variable . The variable names are displayed without the preceding dollar ( $ ) sign that is used to reference variables.

What does $? Mean in PowerShell?

$? Contains the execution status of the last command. It contains True if the last command succeeded and False if it failed. For cmdlets and advanced functions that are run at multiple stages in a pipeline, for example in both process and end blocks, calling this.

How do I get the sign in PowerShell?

ps1. Right-click the script and click on Properties. On the file's Properties window, click the Digital Signatures tab, and you should see a digital signature under the Signature list.

How do you escape a dollar in PowerShell?

Your successful options to escape the dollar sign ($) in PowerShell are to use double quotes with a backslash-backtick combination ("\`$find"), or instead to use single quotes with a simple backslash ('\$find'). [However, note the exception at the end about function call parameters.]


1 Answers

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.

like image 193
Shankar R10N Avatar answered Sep 21 '22 23:09

Shankar R10N