Created
August 10, 2016 02:30
-
-
Save JustinGrote/b98ba81cd6f3cb2c6c7212ccfee22ae3 to your computer and use it in GitHub Desktop.
Get VMware Guest Disk Utilization Report of Virtual Machines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 3.0 | |
#requires -pssnapin vmware.vimautomation.core | |
#Uncomment this on first run for initial connection. Unnecessary for re-runs | |
#connect-viserver d1vm-vc01,d2vm-vc01,d1vm-vcvdi01,d2vm-vcvdi01 -credential (get-credential) | |
$noDiskInfoVMs = @() | |
$vm = get-vm | |
$vm | | |
where guestid -notmatch 'windows7_64Guest' | | |
foreach { | |
$vmItem = $PSItem | |
$vmName = $vmItem.Name | |
if (!($vmItem.ExtensionData.Guest.Disk)) {write-error "$vmName disk info invalid";$noDiskInfoVMs += $vmItem; return} | |
foreach ($vmDiskItem in $vmItem.ExtensionData.Guest.Disk) { | |
[PSCustomObject][ordered]@{ | |
Name = $vmName | |
Diskpath = $vmDiskItem.DiskPath | |
UsedMB = [int][math]::Round(($vmDiskItem.Capacity - $vmDiskItem.FreeSpace)/1MB) | |
CapacityMB = [int][math]::Round($vmDiskItem.Capacity/1MB) | |
UsedPct = [math]::Round((1-($vmDiskItem.FreeSpace / $vmDiskItem.Capacity))),2 | |
FreeMB = [int][math]::Round($vmDiskItem.FreeSpace/1MB) | |
} | |
} | |
} | | |
sort name,diskpath | | |
export-csv -notypeinformation $home\Desktop\VMGuestDiskUsage.csv | |
$noDiskInfoVMs | select name,powerstate, | |
@{Name="ToolsStatus";Expression={$_.extensiondata.guest.toolsstatus}}, | |
@{Name="GuestState";Expression={$_.extensiondata.guest.gueststate}} | | |
sort name | export-csv -NoTypeInformation $home\Desktop\VMGuestNoDiskInfo.csv | |
$noStorageInfoVMs = @() | |
$vm | | |
where guestid -notmatch 'windows7_64Guest' | | |
foreach { | |
$vmItem = $PSItem | |
$vmName = $vmItem.Name | |
if (!($vmItem.ExtensionData.Storage.PerDatastoreUsage)) {write-error "$vmName storage info invalid";$noStorageInfoVMs += $vmItem; return} | |
foreach ($vmDSItem in $vmItem.ExtensionData.Storage.PerDatastoreUsage) { | |
[PSCustomObject][ordered]@{ | |
Name = $vmName | |
Datastore = $vmDSItem.Datastore | |
AllocatedMB = [Math]::Round(($vmDSItem.UnCommitted + $vmDSItem.Committed) / 1MB) | |
UsedMB = [Math]::Round($vmDSItem.Committed / 1MB) | |
} | |
} | |
} | export-csv -NoTypeInformation $home\desktop\VirtualMachineDatastoreUsage.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment