July 31, 2015

SCVMM - Powershel - Checkpoints Size

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

Here is PowerShell script that combines two cmdlets (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 script (instead "| ft -AutoSize").

If you need to quickly calculate 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").

No comments:

Post a Comment