Disk usage of virtual machines through WMI (PowerGadgets)
Description: Read the disk usage via WMI of the
virtual machines and create a PowerGadgets graph
get-wmi-diskusage.ps1:
#--multi
# full is used because of the Get-Credentials CmdLet and
PowerGadgets for the Snapin
#--full
--powergadgets
$cred
= Get-Credential domain\administrator
foreach
($vm in $multi)
{
$vmip = $vm.Guest.IpAddress
$block =
{
#get the disk perf
object
$drives=gwmi Win32_PerfRawData_PerfDisk_LogicalDisk
-Credential $cred -ComputerName $vmip
#Iterate and generate objects for each disk
foreach
($drive
in
$drives)
{
$maxSize=$drive.percentfreespace_base
$usedspace=$( ($maxSize
-
$drive.PercentFreeSpace) / $maxSize )
$driveName=$drive.name
$driveObject
=
new-object object
add-member -inputobject $driveObject
-membertype NoteProperty
-Name Name
-Value $driveName
add-member -inputobject $driveObject
-membertype NoteProperty
-Name "Percent
Full" -Value $usedspace
#uncomment the lines
below to exclude total overall free space from results
if ( $driveName
-ne
"_Total" )
{
write-output $driveObject
}
} #end foreach
}
&$block |
out-chart -values "Percent
Full" -label Name -AxisY_LabelsFormat_Format Percentage -AxisY_Max 1
- title "Disk Usage By Drive"
}
Copyright © 2009 icomasoft ag, Switzerland