try to get the virtual keyboard a number of different ways. This should hopefully work for Windows 7, Window 10 and Windows Server 2016

This commit is contained in:
Taliesin Sisson 2015-12-05 02:31:28 -08:00
parent 056fc59166
commit 4ab2e8b252
1 changed files with 10 additions and 1 deletions

View File

@ -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)
}