问题
Is it possible to open a window in a current Hyper-V VM session with PowerShell Direct? Or maybe I need to rewords the question as - how to run commands in an existing interactive session that's opened with Hyper-V Remote Desktop Connection?
I have an RDP connection to a Windows Server 2019 VM (Hyper-V), and let's say I want to start notepad.exe
from a PowerShell script that runs on a host VM. I want the Notepad window to appear in my current VM's session to take a screenshot (via PowerShell Direct, too, but that's another story).
This snippet starts notepad.exe in background and does not show its window:
Invoke-Command -VMName 'client1.example.com' -Credential $credential -ScriptBlock {
notepad.exe
}
来源:https://stackoverflow.com/questions/62476454/starting-a-gui-application-on-a-guest-vm-with-powershell-direct