【发布时间】:2017-10-01 16:59:24
【问题描述】:
我想从 Windows 命令提示符启动一个 .ps1。我的 Powershell 脚本有一个路径参数。这是我启动 .ps1 的命令行
powershell Set-ExecutionPolicy Unrestricted -scope process ; C:\\MyPowerShell.ps1 -Path \"C:\\Test for my script\test1.txt"
在 MyPowerShell.ps1 中,如果我写入主机路径,我会得到:C:\Test。当第一个空格出现时,它会切断我的字符串。
我怎样才能得到我的完整路径?
谢谢。
【问题讨论】:
-
“我想从 Windows 命令提示符启动一个 .ps1。”为什么?打开 PowerShell,然后运行您的脚本。您不需要 Windows 命令提示符 (cmd.exe)。
-
因为我是从 Jenkins 管道启动它。
-
如果可以启动可执行文件,则不需要 cmd.exe。只需使用适当的参数运行 PowerShell;例如:
powershell.exe -NoProfile -ExecutionPolicy Unrestricted -File C:\MyPowerShell.ps1 -path "C:\test for my script\test1.txt"。运行powershell /?了解如何使用其命令行的详细信息。
标签: string powershell