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.
Thanks
MG
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
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