Created
June 15, 2016 18:00
-
-
Save BenjaminArmstrong/2bf9452608257f80d9a7176e6537913d to your computer and use it in GitHub Desktop.
Sample PowerShell script to check the pixel value of a virtual machine screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VMName = "VM 1" | |
Add-Type -AssemblyName "System.Drawing" | |
$VMCS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$($VMName)'" | |
# Get the resolution of the screen at the moment | |
$video = $VMCS.GetRelated("Msvm_VideoHead") | |
$xResolution = $video.CurrentHorizontalResolution[0] | |
$yResolution = $video.CurrentVerticalResolution[0] | |
function getVMScreenBMP { | |
param | |
( | |
$VM, | |
$x, | |
$y | |
) | |
$VMMS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService | |
# Get screenshot | |
$image = $VMMS.GetVirtualSystemThumbnailImage($VMCS, $x, $y).ImageData | |
# Transform into bitmap | |
$BitMap = New-Object System.Drawing.Bitmap -Args $x,$y,Format16bppRgb565 | |
$Rect = New-Object System.Drawing.Rectangle 0,0,$x,$y | |
$BmpData = $BitMap.LockBits($Rect,"ReadWrite","Format16bppRgb565") | |
[System.Runtime.InteropServices.Marshal]::Copy($Image, 0, $BmpData.Scan0, $BmpData.Stride*$BmpData.Height) | |
$BitMap.UnlockBits($BmpData) | |
return $BitMap | |
} | |
(getVMScreenBMP $VMCS $xResolution $yResolution).GetPixel(1,1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment