I have problems to execute a batch file on a remote server via PowerShell. The user can choose several opinions in a pop-up window like Servername, starting or killing process and Servicename. The chosen items will be saved in variables.
If all items are chosen, I want to merge the strings to one string and execute the batch script which is named like this result string. I try to do it as described in this post, but the batch script won't be executed.
Example:
[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`""
}