PSExec 为 powershell 传递带有空格的参数
PSExec Pass argument with spaces for powershell
使用 PSexec 工具,我在远程计算机上调用 powershell 会话并执行 PS1 脚本。我需要将参数传递给这个 powershell 脚本文件。如果参数不包含 space,它工作正常。如果参数确实包含 space,space 之后的所有内容都将被修剪。
下面是我的命令:
$script="<PATH>"
$args = "%ProjectSourcePath%"
cmd /c %psexecpath% \<REMOTE SERVER> -u <UNAME> -p <PASSWORD> -h "c:\windows\system32\windowspowershell\v1.0\powershell.exe" $script $args
其中 "%ProjectSourcePath%"
是环境变量。
背景:我在 Jenkins 自动构建工具中使用这个命令。并在 Windows Powershell 脚本块中添加了此脚本。
首先,为了直接从命令行 运行 psexec,使用此命令将 sysinternals(或任何你的 psexec 位置)文件夹添加到 PATH
SET PATH=%PATH%;[FOLDER]
接下来,运行命令行...
我创建了一个非常简单的脚本创建文件,其中包含我传递的参数的名称
param (
[string]$name = "defaultname"
)
$array = "string"
$array | out-file "C:\Temp\Script Location$name.txt"
当运行从远程服务器连接它时,我正在执行以下操作:
psexec \build -h "C:\windows\system32\windowspowershell\v1.0\powershell.exe" "-File" "C:\temp\script location\script.ps1" "argument with space"
以名为 "argument with space.txt"
的文件结束
使用 PSexec 工具,我在远程计算机上调用 powershell 会话并执行 PS1 脚本。我需要将参数传递给这个 powershell 脚本文件。如果参数不包含 space,它工作正常。如果参数确实包含 space,space 之后的所有内容都将被修剪。
下面是我的命令:
$script="<PATH>"
$args = "%ProjectSourcePath%"
cmd /c %psexecpath% \<REMOTE SERVER> -u <UNAME> -p <PASSWORD> -h "c:\windows\system32\windowspowershell\v1.0\powershell.exe" $script $args
其中 "%ProjectSourcePath%"
是环境变量。
背景:我在 Jenkins 自动构建工具中使用这个命令。并在 Windows Powershell 脚本块中添加了此脚本。
首先,为了直接从命令行 运行 psexec,使用此命令将 sysinternals(或任何你的 psexec 位置)文件夹添加到 PATH
SET PATH=%PATH%;[FOLDER]
接下来,运行命令行...
我创建了一个非常简单的脚本创建文件,其中包含我传递的参数的名称
param (
[string]$name = "defaultname"
)
$array = "string"
$array | out-file "C:\Temp\Script Location$name.txt"
当运行从远程服务器连接它时,我正在执行以下操作:
psexec \build -h "C:\windows\system32\windowspowershell\v1.0\powershell.exe" "-File" "C:\temp\script location\script.ps1" "argument with space"
以名为 "argument with space.txt"
的文件结束