powershell - 冒号作为参数中的字符串

标签 powershell scripting

有没有办法排除冒号(:),以便您可以通过参数将其打印为字符串?

小例子:

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/

相关文章:

powershell - 什么是 List`1 对象?

powershell - Atom - 无法保存文件 : Permission denied (Windows)

sharepoint - 如何在不安装 sharepoint 的情况下使用 Sharepoint cmdlet?

windows - 在 Windows 批处理文件中的多个命令中使用 powershell 变量

c++ - 如何在 QlikView 中制作自定义数据源?

python - 如何使用 Python 在 FTP 服务器中运行 Python 脚本?

bash - 如何在不实际更改到该目录的情况下从特定目录执行命令

linux - 如何在 Unix 中的嵌套循环中读取两个文件

powershell - 使用 Powershell 更改区域设置

javascript - Unity脚本全局变量