Advertisement
Guest User

Untitled

a guest
May 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. function Get-VMScreenBMP {
  2. [cmdletbinding()]
  3. Param(
  4. [string]$VMName,
  5. [string]$Computername = $env:computername,
  6. [string]$Path,
  7. [switch]$Passthru
  8. )
  9.  
  10. $VMMS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService -ComputerName $Computername
  11. $VMCS = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$($VMName)'" -ComputerName $Computername
  12.  
  13. # Get the resolution of the screen at the moment
  14. $video = $VMCS.GetRelated("Msvm_VideoHead")
  15. $xResolution = $video.CurrentHorizontalResolution
  16. $yResolution = $video.CurrentVerticalResolution
  17.  
  18. # Get screenshot
  19. $image = $VMMS.GetVirtualSystemThumbnailImage($VMCS, $xResolution, $yResolution).ImageData
  20.  
  21. # Transform into bitmap
  22. $BitMap = New-Object System.Drawing.Bitmap -Args $xResolution,$yResolution,Format16bppRgb565
  23. $Rect = New-Object System.Drawing.Rectangle 0,0,$xResolution,$yResolution
  24. $BmpData = $BitMap.LockBits($Rect,"ReadWrite","Format16bppRgb565")
  25. [System.Runtime.InteropServices.Marshal]::Copy($Image, 0, $BmpData.Scan0, $BmpData.Stride*$BmpData.Height)
  26. $BitMap.UnlockBits($BmpData)
  27.  
  28. $bitmap.Save($path)
  29.  
  30. If ($Passthru) {
  31. Get-Item $path
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement