[英]Trying to escape parenthesis when passing arguments in a PowerShell script
I made a PowerShell script that will send a toast notification via/arguments.我制作了一个 PowerShell 脚本,它将通过/参数发送 toast 通知。 In the script, I use the param
function in the beginning of the script something like....this在脚本中,我在脚本的开头使用了param
function 之类的......这个
param($UserID)
Now I open a command prompt to load a PowerShell script and adding these arguments现在我打开一个命令提示符来加载 PowerShell 脚本并添加这些 arguments
powershell C:\file\in\directory\PowershellScript.ps1 -UserID "Mikey (TEST)"
When I sent the prompt over to PowerShell, it gave me this red error that says当我将提示发送到 PowerShell 时,它给了我这个红色错误,上面写着
TEST : The term 'TEST' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:64
Assumingly the parentheses (
)
could be the culprit as PowerShell is thinking of loading a module of some sort instead of applying as a string value.假设括号(
)
可能是罪魁祸首,因为 PowerShell 正在考虑加载某种模块而不是作为字符串值应用。 I even tried escaping the parentheses using the backslash \(TEST\)
but that didn't work either as it said TEST\: The term 'TEST\' is not recognized as the name of a cmdlet, function, script file, or operable program.
我什至使用反斜杠\(TEST\)
尝试使用 escaping 括号,但这也不起作用,因为它说TEST\: The term 'TEST\' is not recognized as the name of a cmdlet, function, script file, or operable program.
. .
Is there something I'm missing or something part of a script I should add to?有什么我遗漏的东西或我应该添加的脚本的一部分吗?
Use single quotes inside the ps command:在 ps 命令中使用单引号:
powershell C:\file\in\directory\PowershellScript.ps1 -UserID 'Mikey (TEST)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.