Take a screenshot of a Hyper-V virtual machine guest using WMI and Invoke-CimMethod

Using the CIM cmdlets it's possible to take a screenshot of a virtual machine with the GetVirtualSystemThumbnailImage method. 

This needs to be run on the Hyper-V host as a user with Administrator rights.


$managementService = Get-CimInstance -Namespace "root\virtualization\v2" -ClassName "Msvm_VirtualSystemManagementService";

$vm = Get-CimInstance -Namespace "root\virtualization\v2" -ClassName "Msvm_ComputerSystem" -Filter "Name='$VirtualMachineIdentifier'";

$videoHead = Get-CimAssociatedInstance -ResultClassName "Msvm_VideoHead" -InputObject $vm;

$xResolution = $videoHead.CurrentHorizontalResolution;

$yResolution = $videoHead.CurrentVerticalResolution;

$result = Invoke-CimMethod -MethodName "GetVirtualSystemThumbnailImage" -InputObject $managementService -Arguments @{ TargetSystem = $vm; WidthPixels = $xResolution; HeightPixels = $yResolution };


The data returned then needs to be turned into a bitmap image.

Comments

Popular posts from this blog

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

TFTPD32 or TFTPD64 reports Bind error 10013 An attempt was made to access a socket in a way forbidden by its access permissions.

Windows Server 2019 desktop icons such as My Computer, Windows cannot access the specified device, path, or file.