Send Keystrokes/Text to a VM through VMBus (Virtual-Key/Console Keyboard)

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
$Node = <"Hyper-V Node">
$VM = <"VM">
$ComputerSystem = Get-WmiObject -ComputerName $Node -Query "select * from Msvm_ComputerSystem where ElementName = '$VM'" -Namespace "root\virtualization\v2"
$Keyboard = Get-WmiObject -ComputerName $Node -Query "ASSOCIATORS OF {$($ComputerSystem.path.path)} WHERE resultClass = Msvm_Keyboard" -Namespace "root\virtualization\v2"
 
$Keyboard.InvokeMethod("TypeText","Hello world!") # Type 'Hello World!'
$Keyboard.InvokeMethod("TypeKey","13") # Press enter
$Keyboard.TypeCtrlAltDel() # Send Ctrl + Alt + Del




Virtual-Key Codes: