PoshCode Archive  Artifact [720e0ab8f9]

Artifact 720e0ab8f91900b5ac567b5c3c89d817e9fd8b779a7f60e608cd84a1b74749d5:

  • File Get-VMDiskUsagePerDS.ps1 — part of check-in [60a5b27c0c] at 2018-06-10 14:06:36 on branch trunk — Fetches the per-datastore disk utilization of a virtual machine. Is thin-provisioning aware and reports only the thin provisioned used space for UsedGB. (user: Justin Grote size: 1179)

# encoding: ascii
# api: powershell
# title: Get-VMDiskUsagePerDS
# description: Fetches the per-datastore disk utilization of a virtual machine. Is thin-provisioning aware and reports only the thin provisioned used space for UsedGB.
# version: 0.1
# author: Justin Grote
# license: CC0
# x-poshcode-id: 6034
# x-archived: 2016-05-17T09:11:42
# x-published: 2016-09-30T23:02:00
#
#
$views = (get-vm | get-view)
$views += (get-template | get-view)

$VMDatastores = get-datastore

$views | foreach {

    $vm = $PSItem

     foreach ($VMDSUsage in $vm.storage.PerDatastoreUsage) {
        $dsReport = [ordered]@{}
        $VMDatastore = $VMDatastores | where { $_.ID -match "datastore-$($VMDSUsage.datastore.value)"}
        $dsReport.VMName = $vm.name
        $dsReport.Datastore = $VMDatastore.Name
        $dsReport.UsedGB = [math]::round(($VMDSUsage.committed / 1GB),2)
        $dsReport.ProvisionedGB = [math]::round((($VMDSUsage.committed + $VMDSUsage.Uncommitted) / 1GB),2)
        $dsReport.DatastoreUsagePct = [math]::round((($dsReport.UsedGB / $VMDatastore.CapacityGB) * 100),2)
        new-object PSObject -property $dsReport
    }


}