有没有办法排除冒号(:
),以便您可以通过参数将其打印为字符串?
小例子:
PowerShellTest.ps1:
param (
[string]$message="Error: No message defined!"
);
"Info: Test-Information"
$message;
如果您现在通过 powershell 启动此脚本:
powershell.exe D:\PowerShellTest.ps1 -message "Error: Test-Error"
现在你只得到输出字符串错误:
其余部分将被切断
我需要做什么才能获取整个字符串错误:测试错误
?
最佳答案
问题不是冒号,而是空格。您需要使用反引号对其进行转义:
powershell.exe D:\PowerShellTest.ps1 -message 'Error:` Test-Error'
关于powershell - 冒号作为参数中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698144/