Skip to content

Commit 073b1ea

Browse files
committed
Get-VMFootprintByEnv.ps1 script added
1 parent 99467d5 commit 073b1ea

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#requires -runasadministrator
2+
#requires -modules ActiveDirectory
3+
4+
#
5+
# Paolo Frigo, https://www.scriptinglibrary.com
6+
# This script will sum all VM Footprint according to the filter PROD/TEST/DEV used.
7+
#
8+
9+
10+
$Filter = "prod" # prod, test or dev
11+
$VMNODES = "VMNode-01", "VMNode-02", "VMNode-03" #get-adcomputer -filter {name -like "My_Naming_Convention"} | Select-object -expandproperty name
12+
$Result = 0
13+
14+
foreach ($VMHost in $VMNODES) {
15+
if (Test-Connection $VMHost -Quiet -Count 1) {
16+
$VM = get-vm -computername $VMHost | Where-Object {$_.name -match "$Filter"}
17+
$Disks = $VM | Get-VMHardDiskDrive | Select-object -expandproperty path
18+
$total_size = Invoke-Command -ComputerName $VMHost -ScriptBlock {
19+
param($Disks)
20+
$total = 0
21+
#write-host $disks
22+
foreach ($disk in $disks) {
23+
$size = [math]::round((get-item -Path $disk | select-object -ExpandProperty length)/1GB,2)
24+
write-host "Disk: $disk `t Size $size GB"
25+
$total += $size
26+
}
27+
return $total
28+
} -ArgumentList (,$Disks)
29+
$Result += $total_size
30+
}
31+
else {
32+
raise "$VMHost is not reachable"
33+
}
34+
}
35+
36+
Write-Output "$Filter VM footprint is $Result GB".ToUpper()

0 commit comments

Comments
 (0)