Mosa1c2 – As seen on MMS2012


Mosa1c2

All attendees of MMS2012 have noticed big screen next to labs, where thumbnails of all running virtual machines were live displayed and you could see what has been happening on console display of each virtual server.

image

I found that screen fascinating, and I also wanted to have »one form y self« our office next to SCOM screen. Despite searching online, I could find nothing similar, just mentioning of Mosaic product announcement on MMS2011, but not a word of actual release ever since.

So…
Once upon a time, while waiting for user confirmation of BCP tests, I had some time to spare….
… I dived into work and prepared me desired view.

I am sure there are also couple of you who would also like to have this, so I am sharing my solution.

With partially adopted PowerShell script from Taylor Brown (http://blogs.msdn.com/b/taylorb/archive/2008/07/29/hyper-v-wmi-creating-a-thumbnail-image.aspx) and am running it over scheduled tasks every 5 minutes.

PowerShell script:

Import-Module virtualmachinemanagercore
Import-Module virtualmachinemanager
[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing)

$ImagePath = “C:\inetpub\wwwroot”
$xRes = 160
$yRes = 120

#get name of all HyperV hosts

Get-VMHost | where-object {$_.VirtualizationPlatform -eq “HyperV”} | foreach {
$HyperVParent = $_.name

#prepare thumbnails of all virtual machines and drops it to desired path

Get-VM | where-object {$_.HostName -eq $HyperVParent}|foreach {
   $HyperVGuest = $_.Name
$VMManagementService = Get-WmiObject -class “Msvm_VirtualSystemManagementService” -namespace “root\virtualization” -ComputerName $HyperVParent
$Vm = Get-WmiObject -Namespace “root\virtualization” -ComputerName $HyperVParent -Query “Select * From Msvm_ComputerSystem Where ElementName=’$HyperVGuest’”
$VMSettingData = Get-WmiObject -Namespace “root\virtualization” -Query “Associators of {$Vm} Where ResultClass=Msvm_VirtualSystemSettingData AssocClass=Msvm_SettingsDefineState” –ComputerName $HyperVParent
$RawImageData = $VMManagementService.GetVirtualSystemThumbnailImage($VMSettingData, “$xRes”, “$yRes”)

$VMThumbnail = new-object System.Drawing.Bitmap($xRes, $yRes, [System.Drawing.Imaging.PixelFormat]::Format16bppRgb565)

$rectangle = new-object System.Drawing.Rectangle(0,0,$xRes,$yRes)
[System.Drawing.Imaging.BitmapData] $VMThumbnailBitmapData = $VMThumbnail.LockBits($rectangle, [System.Drawing.Imaging.ImageLockMode]::WriteOnly, [System.Drawing.Imaging.PixelFormat]::Format16bppRgb565)
[System.Runtime.InteropServices.marshal]::Copy($RawImageData.ImageData, 0, $VMThumbnailBitmapData.Scan0, $xRes*$yRes*2)
$VMThumbnail.UnlockBits($VMThumbnailBitmapData);

$VMThumbnail
$VMThumbnail.Save(“$ImagePath\$HyperVGuest.jpg”)
}

}

#Create HTML with thumbnails

Get-ChildItem $ImagePath -Recurse -Include “*.jpg” | foreach-object {‘<img src=”‘ + $_.Name + ‘” alt=”‘ + $_.BaseName+‘” />’} | Out-file -filepath “$ImagePath\thumbs.html” -encoding ASCII

 

Besides creating JPG Thumbnails, script also prepares HTML where VMs are displayed in alphabetical order.
To make it all more neatly and assure refreshment of internet page I made small page, which can add also some additional information to displayed page and am running it on VMM server.

Default.asp:

<HTML>
<TITLE>Mosa1c2</TITLE>
<HEAD>
<META HTTP-EQUIV=”PRAGMA” CONTENT=”NO-CACHE”>
<META HTTP-EQUIV=”REFRESH” CONTENT=”20″>
</HEAD>

<BODY>

<!–#include virtual=”thumbs.html”–>
<br /> <H2><p style=”text-align: center;”> <% Response.Write(Time) %></H2>

</BODY>
</HTML>

 

Feel free to adopt code to your specific needs.

Happy usage,
Matjaž

email

Written by , Posted .