0

Is there a way to run a command in a specific Command Prompt window using its Process ID?

$command = "C:\Windows\system32\cmd.exe" $ID = (Start-Process -FilePath $Command -PassThru).Id Write-Host $ID $command = "mycommandgoeshere" $process = Get-WmiObject Win32_Process -Filter "ProcessId=$ID" $process.InvokeMethod("Create", $command) 

However, it is failing with the error
NotSpecified: Exception calling "InvokeMethod" with "2" argument(s): "Invalid method "

I'm looking for a way to run commands on a remote server in the same command window. Thank you!

8
  • You don't need CMD at all to run commands on a remote machine at all, you know that, right? Regardless of that - why did you add the tags for different PowerShell versions? Are you asking for a specific version? If not you should remove these tags. Thanks in advance. 👍🏼 Commented Nov 25, 2024 at 20:32
  • @Olaf Thank you for your response. I removed the version specific powershell tags. Here is what I'm trying to achieve. Octopus is the orchestrator - Run a ps1 command on a remote server (Step1) - Execute a bunch of other stuff, deployments etc - Run another ps1 from the same window as Step1 Commented Nov 25, 2024 at 20:35
  • I don't know octopus ... why you need to run it from the same window? If you need to run stuff in sequence just run it in sequence. 🤷🏼‍♂️ Commented Nov 25, 2024 at 20:39
  • We are trying to deploy to a VMWare capture machine. It involves running Start-AVAppCapture command, install the application and run Stop-AVTask to create the VHD file. But Stop-AVTask should be run from the same session that ran Start-AVAppCapture Commented Nov 25, 2024 at 20:43
  • I have no experiences with VMWare but I don't see the issue. You can run whatever you want from within the same script/session. 🤷🏼‍♂️ ... I guess I'm missing something. 🤔 Commented Nov 25, 2024 at 21:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.