简体   繁体   English

在 PowerShell 中的密码变量中包含 $ 符号

[英]To include $ symbol in password variable in PowerShell

I'm trying to pass a password variable in my PowerShell script like below:我正在尝试在我的 PowerShell 脚本中传递一个密码变量,如下所示:

[string] $username,
[string] $password

My password includes $ symbol in it.我的密码中包含 $ 符号。 When I try to call the script by passing password like below.当我尝试通过传递如下密码来调用脚本时。

& "script.ps1" -username "admin" -password "Pa$$word"

but in the script my password is read like below:但在脚本中,我的密码如下所示:

password = Paword

Is there a way to include $ symbol in my variable?有没有办法在我的变量中包含 $ 符号? I tried adding '\\' symbol before $ but still it is not being read properly.我尝试在 $ 之前添加 '\\' 符号,但仍然无法正确读取。

在单引号中传递密码为:

& "script.ps1" -username "admin" -password 'Pa$$word'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM