Whenever I go to a new customer with a Hyper-V and SCVMM environment, there are a bunch of scripts I run in order to get a view of their environment.
One of those is to get all VM’s, the the VHD sizes and when there is a Dynamic VHD the appropiate information (size, maximum size, free space, percentage in use) is shown in red.
Why red? Because I don’t think that using Dynamic VHD’s in a production environment, with the current release of Hyper-V, is not the best road to take.
The script provides an output like:
Image may be NSFW.
Clik here to view.
I hope you find the following usefulImage may be NSFW.
Clik here to view. Here’s the code:
$VMS = Get-VM -VMMServer localhost | Sort-Object -Property Name -Descending
“<HTML><HEAD><TITLE>VM Inventory</TITLE></HEAD><BODY><TABLE BORDER=1>” | Out-File $Env:Temp\VMInventory.html
“<TR><TD>VM Name</TD><TD>VM Memory</TD><TD>VHD Name</TD><TD>VHD Length</TD><TD>VHD Maximum</TD><TD>VHD Available</TD><TD>VHD Free %</TD></TR>” | Out-File $Env:Temp\VMInventory.html -Append
foreach ($VM in $VMS)
{
“<TR><TD>”+$VM.Name+”</TD><TD>”+$VM.Memory+”MB</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD><TD>.</TD></TR>” | Out-File $Env:Temp\VMInventory.html -Append
foreach ( $VHD in $VM.VirtualHarddisks)
{
$VHDLength = ($VHD.Size / 1GB)
$VHDSize = “{0:N2}” -f $VHDLength
if ($VHD.VHDType -eq “DynamicallyExpanding”)
{
$BackgroundColor = “#FF0000″
$VHDMaximumSize = “{0:N2}” -f ($VHD.MaximumSize / 1GB)
$VHDAvailable = “{0:N2}” -f (($VHD.MaximumSize – $VHD.Size) /1GB)
$VHDFree = “{0:N2}” -f (100 – (($VHD.Size * 100) / $VHD.MaximumSize))
“<TR><TD>.</TD><TD>.</TD><TD bgcolor=”+$BackgroundColor+”>”+$VHD.Name+”</TD><TD bgcolor=”+$BackgroundColor+”>”+$VHDSize+”GB</TD><TD bgcolor=”+$BackgroundColor+”>”+$VHDMaximumSize+”</TD><TD bgcolor=”+$BackgroundColor+”>”+$VHDAvailable+”</TD><TD bgcolor=”+$BackgroundColor+”>”+$VHDFree+” %</TD></TR>” | Out-File $Env:Temp\VMInventory.html -Append
}
else
{
“<TR><TD>.</TD><TD>.</TD><TD>”+$VHD.Name+”</TD><TD>”+$VHDSize+”GB</TD><TD>.</TD><TD>.</TD><TD>.</TD></TR>” | Out-File $Env:Temp\VMInventory.html -Append
}
}
“<TR>” | Out-File $Env:Temp\vminventory.html -Append
}
“</TABLE><BODY></HTML>” | Out-File $Env:Temp\VMInventory.html -Append
Invoke-Expression $Env:Temp\vminventory.html