VMware Cloud Community
imtrinity94
Enthusiast
Enthusiast
Jump to solution

Used Space of a multi-datastore connected VM per datastore wise | PowerCLI

Hi Someone,

I am looking for powercli commands to get the used space of a VM associated with a particular datastore. And I want this into a csv for all datastores to which the VM has some storage attached.

pastedImage_0.png

Thanks

MG


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$vmName = 'MyVM'

$props = 'Name','Storage.PerDatastoreUsage'

$report = foreach($vm in (Get-View  -ViewType VirtualMachine -filter @{"Name"=$vmName} -Property $props)){

        $vm.Storage.PerDatastoreUsage |

        Select @{N='VM';E={$vm.Name}},

            @{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},

            @{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},

            @{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},

            @{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}

}

$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$vmName = 'MyVM'

$props = 'Name','Storage.PerDatastoreUsage'

$report = foreach($vm in (Get-View  -ViewType VirtualMachine -filter @{"Name"=$vmName} -Property $props)){

        $vm.Storage.PerDatastoreUsage |

        Select @{N='VM';E={$vm.Name}},

            @{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},

            @{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},

            @{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},

            @{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}

}

$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos