Skip to content

Commit 886db8c

Browse files
committed
get-vmfootprintonasinglehost.ps1 script added and description edited.
1 parent 8924fe1 commit 886db8c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Blog/PowerShell/Get-VMFootprintByEnv.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
#
55
# Paolo Frigo, https://www.scriptinglibrary.com
6-
# This script will sum all VM Footprints according to the filter PROD/TEST/DEV used.
7-
#
6+
# This script will sum all VM Footprints according to your naming convention filter PROD/TEST/DEV used.
7+
#
8+
# VMNODES will list all hyper-v hosts
89

910

1011
$Filter = "prod" # prod, test or dev
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#requires -runasadministrator
2+
3+
#
4+
# Paolo Frigo, https://www.scriptinglibrary.com
5+
# This script will get the size of all VHDX files of all VMs hosted on your Hyper-V
6+
#
7+
# notes - Please have a look to get-vmfootprintbyenv.ps1 in case you want to run this
8+
# script against multiple hyper-v hosts
9+
10+
function Get-VMFootprint ($VM){
11+
$total_size = 0
12+
foreach ($disk in ($VM | Get-VMHardDiskDrive | Select-object -expandproperty path) ){
13+
$total_size += Get-Item $disk | Select-Object -ExpandProperty Length
14+
}
15+
Return [math]::round($total_size/1GB,2)
16+
}
17+
18+
$couter = 0
19+
$vm_counter = 0
20+
$total = 0
21+
22+
foreach ($VMHost in $ALL_HSD_VM_NODES){
23+
$counter += 1
24+
foreach ($VM in (get-vm -computername $VMHost)){
25+
$vm_counter += 1
26+
Write-Progress -Status "Get Footprint of $($VM.Name)" -Activity "Retrieve information from $($VmHost)" -PercentComplete $($couter/$NumNodes*100)
27+
$VmSize = $(Get-VMFootprint($VM))
28+
Write-Verbose "$($VM.Name) - $VmSize GB"
29+
$total += $VmSize
30+
}
31+
}
32+
33+
Write-Output "$vm_counter VMs Footprint: $total GB "

0 commit comments

Comments
 (0)