Hyper-V Get Snapshot checkpoint file sizes on Cluster Shared Volumes with PowerShell

During a Windows Server 2012 Hyper-V Health Check I needed to know the snapshot file sizes for the all the snapshots on the Clustered Shared Volumes (CSVs). The Get-VMCheckpoint Cmdlet does not report the snapshot size. So I create a PowerShell one-liner that displays the following information:

  • Location of the snapshot file
  • Date and time that the snapshot file was created
  • Last write access time of the snapshot file
  • File size in MBs

The PowerShell one-liner is executed from a Hyper-V 2012 host that has access to all the  Cluster Shared Volumes (CSVs).

Get-ChildItem C:\ClusterStorage\ * -include *.avhd -recurse  | Select-Object Fullname,CreationTime,LastWriteTime,@{"Name"="Size (MB)"; "Expression"={[int]($_.Length/1mb)}} | Out-GridView

This PowerShell one-liner produces the following output:

Health Check your System Center Virtual Machine Server (SCVMM) 2012 environent with PowerShell

Last week I created a simple example of a Healt Check PowerShell script that connects to Microsoft System Center Virtual Machine Manager and displays information about the Hyper-V hosts and VMs managed by this server. 

I run the PowerShell script  from another Windows Server 2012 host. To make this work make sure the Hyper-V manager and the VMM Console is installed on the server. The VMM console can be installed from the Microsoft System Center 2012 Virtual Machine Manager ISO.

The output is displayed on the screen and exported to a HTML file. The following information is generated:

Host information:

Cluster it belongs, host name, CPU count, core count, CPU speed, CPU model, memory, operating System, and VM hostgroup

VM information:

VM name, computer name, host the VM is on, CPU count, CPU type, memory, if dynamic Memory is enabled, Operating System, If integration tools are installed, integration tool version, VM status, Replication Status and VM location

VM snapshot information:

VM Name, Name of the snapshot, description, time added and modified time

Here is an example how the output looks like:


The only parameter that needs to be changed is the $File variable that specify the location were the HTML file is stored.

PowerShell script:

  System Center Virtual Machine Manager Healthcheck 
  Generates a HTML Healthcheck report 
  Author(s): Ivo Beerens 
  PS> ./scvmmhc.ps1

# Import modules
Import-Module -Name "Hyper-v"
Import-Module -Name "VirtualMachineManager"

$Date = Get-Date
$Datefile = ( get-date ).ToString('yyyy-MM-dd-hhmmss')
$File = New-Item -type file "D:\Temp\Healtcheck_$datefile.html"

#Connect to the SCVMM server
$VMMName = Read-Host "Enter System Center Virtual Machine Server Name to check"
Write-Host "VMM name is $VMMName" -ForeGround Red 
Get-VMMServer -ComputerName $VMMName

# Add Text to the HTML file 

Function Create-HTMLTable
    $arrHTML = $Array | ConvertTo-Html
    $arrHTML[-1] = $arrHTML[-1].ToString().Replace('</body></html>',"")
    Return $arrHTML[5..2000]

$output = @()
$output += '<html><head></head><body>'
$output += 
$output += '<h1>Hyper-V health check</h1>'
$output += '<h1>Versie 1.0</h1>'
$output += '<h2>Date and time</h2>',$date

# Hosts
$HVHosts = Get-VMHost | Select HostCluster,Name,PhysicalCPUCount,CoresPerCPU,ProcessorManufacturer,CPUSpeed,CPUModel,@{N="Memory(GB)";E={[math]::Round((($_.TotalMemory)/1GB),3)}},OperatingSystem,EnableLiveMigration,VMHostGroup
$output += '<p>'
$output += '<h1>Hosts</h1>'
$output += '<p>'
$output += Create-HTMLTable $HVHosts
$output += '</p>' 

# VM
$VMs = Get-VM | Select Name,ComputerName,HostName,CPUCount,CpuType,MemoryAssignedMB,DynamicMemoryEnabled,OperatingSystem,HasVMAdditions,VMAddition,VirtualMachineState,Status,ReplicationStatus,Location
$output += '<p>'
$output += '<h1>VMs</h1>'
$output += '<p>'
$output += Create-HTMLTable $VMs
$output += '</p>'

# Snapshots
$VMSnaps = Get-VM | Get-VMCheckpoint | Select VM,Name,Description,AddedTime,ModifiedTime 
$output += '<p>'
$output += '<h1>Snapshots</h1>'
$output += '<p>'
$output += Create-HTMLTable $VMSnaps
$output += '</p>'

# End
$output += '</body></html>'    
$output | Out-File $file -Force

# Open the HTML file
ii $file

The script can be easily extended with other checks, for example an e-mail option. If you have other additions let me know so the script can be extended.

Identify NICs in Hyper-V 2012

In a Hyper-V cluster are normally a lot of NICs involved. Identifying the right can be challenging. It is important to consequently label your network adapters on all the servers in the Hyper-V cluster.

In Windows Server 2012 there are PowerShell Cmdlets that can be used for identifying NICs.  Once you identified the NIC, rename it to meaningful name.   The PowerShell Cmdlets listed below can be executed on the following versions:

– Windows Server 2012 with the Hyper-V role

– Hyper-V Server 2012


Here are three ways listed using PowerShell to identify the NIC in a Windows Server 8 Hyper-V environment.

Before you begin

Execute PowerShell and import the Hyper-V module using the following command:

Import-Module Hyper-V

1. Identify the NIC by connection State

Connect one NIC and use the following command:

Get-NetAdapter | Select Name, InterfaceDescription, MediaConnectionState | FL

Look at which NIC is connected and rename the NIC to a meaningful name (listed below)


Add the second NIC and execute the command again and rename the name of the NIC. Do this for all NICs

2. Identify the NIC using the MAC address

When you know the MAC address of the NIC (for example in a HP Flex-10 environment) it can be identified using the following command:

Get-NetAdapter | Select Name, InterfaceDescription, MacAddress | FL


Look at the corresponding MAC address  and rename the NIC to a meaningful name (listed below). Do this for all NICs.

3. Identify the NIC by PCI bus ID

The last option is to identify the NIC by PCI bus ID. The following command list all NICs PCI bus adapter information:

Get-NetAdapterHardwareInfo | select Name, InterfaceDescription, DeviceType, 
Busnumber, Devicenumber, Functionnumber | FL


Look at the corresponding PCI bus and rename the NIC to a meaningful name (listed below). Do this for all NICs.

Rename the NIC

Rename the NIC to a meaningful name, for example, rename the name “Wired Ethernet Connection 2” to “MGMT-LOM01-VLAN20” use the following command:

Rename-NetAdapter “Wired Ethernet Connection 2” –NewName “MGMT-LOM01-VLAN20”