How to get specific VM disk space details using get-view filter

When I looking for monitoring the Windows based VM Disk Usage report,I came across the solution using PowerCLI,well lastest RVtools version does the same but it will pull all the VM disk usage not the specific VM.Using VMware tools + powercli you can able to pull the disk usage of Windows or Unix VM.

PowerCLI Script:

#Credits to Alan http://www.virtu-al.net/
#Modified by Deepak
#Prequisties need VMware Tools in VM to monitor the Disk
$vc= ‘192.168.1.6’
$vcuser=”root”
$vcpass=”kolaveri”
#Connecting the VC
Connect-VIServer -Server $vc -User $vcuser -Password $vcpass
$DiskUtil = @()
#Collecting all VM in VC
$AllVMs = Get-View -ViewType VirtualMachine -Filter @{“Name” = “do*”}
#Inplace “Do” we need to mention “MT”
$SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VM in $SortedVMs){
$Details = New-object PSObject
$Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty
$DiskNum = 0
Foreach ($disk in $VM.Guest.Disk){
$Details | Add-Member -Name “Disk$($DiskNum)path” -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name “Disk$($DiskNum)Capacity(GB)” -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1GB))
$Details | Add-Member -Name “Disk$($DiskNum)FreeSpace(GB)” -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1GB))
$DiskNum++
}
$DiskUtil += $Details
}
$DiskUtil | Export-Csv DiskUtil.csv

Credits goes to PowerCli Guru Alan and LucD

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s