Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-VMScreenBMP {
- [cmdletbinding()]
- Param(
- [string]$VMName,
- [string]$Computername = $env:computername,
- [string]$Path,
- [switch]$Passthru
- )
- $VMMS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService -ComputerName $Computername
- $VMCS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$($VMName)'" -ComputerName $Computername
- # Get the resolution of the screen at the moment
- $video = $VMCS.GetRelated("Msvm_VideoHead")
- $xResolution = $video.CurrentHorizontalResolution
- $yResolution = $video.CurrentVerticalResolution
- # Get screenshot
- $image = $VMMS.GetVirtualSystemThumbnailImage($VMCS, $xResolution, $yResolution).ImageData
- # Transform into bitmap
- $BitMap = New-Object System.Drawing.Bitmap -Args $xResolution,$yResolution,Format16bppRgb565
- $Rect = New-Object System.Drawing.Rectangle 0,0,$xResolution,$yResolution
- $BmpData = $BitMap.LockBits($Rect,"ReadWrite","Format16bppRgb565")
- [System.Runtime.InteropServices.Marshal]::Copy($Image, 0, $BmpData.Scan0, $BmpData.Stride*$BmpData.Height)
- $BitMap.UnlockBits($BmpData)
- $bitmap.Save($path)
- If ($Passthru) {
- Get-Item $path
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement