【发布时间】:2026-01-04 08:25:01
【问题描述】:
我无法通过 PowerShell 在远程服务器上执行批处理文件。用户可以在弹出窗口中选择多个意见,如Servername、starting 或killing 进程和Servicename。选择的项目将保存在变量中。
如果选择了所有项目,我想将字符串合并为一个字符串并执行命名为这个结果字符串的批处理脚本。 我尝试按照this post 中的说明进行操作,但不会执行批处理脚本。
例子:
[String]$scriptpath="C:\tmp\"
[String]$Servername = "xx040"
[String]$actionprefix = "kill_process"
[String]$action = $($actionprefix) + "-"
[String]$Servicename = "service1"
[String]$ServiceFullname = $($action) + $($Servicename) + ".bat"
$batchPath = $("`"$scriptpath + $ServiceFullname `"")
Invoke-Command -ComputerName $Servername -ScriptBlock {
cmd.exe /c "`"$batchPath`""
}
【问题讨论】:
标签: windows powershell batch-file cmd