在PowerShell的password变量中包含$符号

时间:2019-12-24 10:13:00

标签: powershell

我正在尝试在PowerShell脚本中传递密码变量,如下所示:

[string] $username,
[string] $password

我的密码中包含$符号。当我尝试通过如下所示的密码来调用脚本时。

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

但是在脚本中,我的密码如下所示:

password = Paword

是否可以在变量中包含$符号?我尝试在$之前添加'\'符号,但仍无法正确读取。

1 个答案:

答案 0 :(得分:0)

以单引号将密码传递为:

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