From 4ab2e8b2524b8db0198b7e5513557bd341a3270d Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sat, 5 Dec 2015 02:31:28 -0800 Subject: [PATCH] try to get the virtual keyboard a number of different ways. This should hopefully work for Windows 7, Window 10 and Windows Server 2016 --- powershell/hyperv/hyperv.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/powershell/hyperv/hyperv.go b/powershell/hyperv/hyperv.go index 2c040a0bf..41556ba64 100644 --- a/powershell/hyperv/hyperv.go +++ b/powershell/hyperv/hyperv.go @@ -682,8 +682,17 @@ param([string]$vmName, [string]$scanCodes) if ($vm -eq $null){ Write-Error ("VirtualMachine({0}) is not found!" -f $VMName) } - + $vmKeyboard = $vm | Get-CimAssociatedInstance -ResultClassName "Msvm_Keyboard" -ErrorAction Ignore -Verbose:$false + + if ($vmKeyboard -eq $null) { + $vmKeyboard = Get-CimInstance -Namespace "root\virtualization\v2" -ClassName Msvm_Keyboard -ErrorAction Ignore -Verbose:$false | where SystemName -eq $vm.Name | select -first 1 + } + + if ($vmKeyboard -eq $null) { + $vmKeyboard = Get-CimInstance -Namespace "root\virtualization" -ClassName Msvm_Keyboard -ErrorAction Ignore -Verbose:$false | where SystemName -eq $vm.Name | select -first 1 + } + if ($vmKeyboard -eq $null){ Write-Error ("VirtualMachine({0}) keyboard class is not found!" -f $VMName) }