2
votes

I got a powershell script to generate an HTML report includes all VM's and snapshots of one hyper-v server.

At first I get all vms with Get-VM. Then I loop through that list and get all snapshots for one vm with Get-VMSnapshot.

The problem that I got is, that i can't see how I get from $VMSnapshot to the real file to get its size.

Here is my code:

$VMs = Get-VM -ComputerName $Computers
foreach ($VM in $VMs) {
    $VMSnapshots = Get-VMSnapshot -VMName $VM.VMName -ComputerName $VM.ComputerName | Select ComputerName, VMNAME, CreationTime, Path, Name | sort CreationTime
    foreach ($VMSnapshot in $VMSnapshots) {
        #How to get the filesize of that snapshot?
    }
}

I know, that its possible to get the filesize with $VMSnapshotSize gci -Path $VMSnapshot.Path -Filter *.avhd*, but than I don't have relationship between $VMSnapshot and $VMSnapshotSize since there is more than one snapshot in that directory.

1

1 Answers

1
votes

Try this code:

Get-VMSnapshot -VMName $VM.VMName | select -ExpandProperty HardDrives | % { Get-VHD $_.Path | select Path, FileSize }