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
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.
$? 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.
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.
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.]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With