File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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)/ 1 GB , 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()
You can’t perform that action at this time.
0 commit comments