Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Hyper-V Report - Checkpoints Size

This script checks all your standalone or clustered Hyper-V servers for existing VM checkpoints.

It checks only Hyper-V servers that are managed by System Center 2012 R2 Virtual Machine Manager so Virtual Machine Manager Command Shell is required. Otherwise this script will fail.

Report contains information about Virtual Machine Name (VMName), its state (VirtualMachineState), Hyper-V hostname where VM is running (HostName), snapshot file location (Location) and the snapshot size. Size values are converted to MB and sorted by size.

You can use CheckpointSize.ps1 simply by running it. Result output will be in table format. Also you can specify -File parameter to export data into CSV file.

Example

.\CheckpointSize.ps1 -File "C:\YourFolder\CheckpointSize.csv"

Script logic

Virtual Machine Manager Command Shell has great cmdlet Get-SCVMCheckpoint. It allows seeing snapshots across your Hyper-V hosts that managed via VMM. I noticed one limitation of that cmdlet. It actually doesn't show the size of checkpoints. I looked into cmdlet's available in Command Shell and noticed Get-SCVirtualHardDisk command that has size information I need.

Here is PowerShell script that combines two cmdlet's (Get-SCVirtualMachine and Get-SCVirtualHardDisk) to search all virtual machines with .avhd drive. It includes VMName and VirtualMachineState properties from Get-SCVirtualMachine part. HostName, Location of AVHD* file and Size are populated from Get-SCVirtualHardDisk part. Results are sorted by Size and default Bytes expression converted to Megabytes.

Get-SCVirtualMachine | foreach {$VMName = $_.name; $VirtualMachineState = $_.VirtualMachineState; Get-SCVirtualHardDisk -VM $_.name | where {$_.Location -like "*.avhd*"} | select @{Name='VMName'; Expression={[String]::join(";", $VMName)}},@{Name='VirtualMachineState'; Expression={[String]::join(";", $VirtualMachineState)}},HostName,Location,@{"Name"="Size (MB)"; "Expression"={[int]($_.Size/1MB)}}} | sort "Size (MB)" -Descending | ft -AutoSize

Results can be exported to CSV file by adding " | export-csv filename.csv" at the end of the script (instead "| ft -AutoSize").

If you need to quickly calculate the results and see an output you can use measure function "| measure "Size (MB)" -Ave -Sum -Max -Min" at the end of script (instead of " | sort "Size (MB)" -Descending | ft -AutoSize").