Hi people,
Could you please assist me in generating the report of VM and its Datastore location (with Data store Free Space, Provisioned Size and Usage). ?
Ideally it should go like this:
VM Name | Datastore Name | Datastore Size | DataStore Total Provisioned size
Thanks
The following script adds the ProvisionedSpaceGB property to the output of Luc's script:
Get-VM | ForEach-Object { if ($_) { $vm = $_ $vm | Get-Datastore | ForEach-Object { if ($_) { $Datastore = $_ "" | Select-Object -Property @{N="VM name";E={$vm.Name}}, @{N="ProvisionedSpaceGB";E={$vm.ProvisionedSpaceGB}}, @{N="Datastore Name";E={$Datastore.Name}}, @{N="Datastore Size (GB)";E={[Math]::Round($Datastore.CapacityMB/1KB,0)}}, @{N="Datastore Total Provisioned size (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB+$Datastore.ExtensionData.Summary.Uncommitted/1GB,0)}}, @{N="Datastore Used Space (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB,0)}} } } } }
Hi Albert,
the next PowerCLI script will give you the desired VM and datastore information:
Get-VM | ForEach-Object { if ($_) { $vm = $_ $vm | Get-Datastore | ForEach-Object { if ($_) { $Datastore = $_ "" | Select-Object -Property @{N="VM name";E={$vm.Name}}, @{N="Datastore Name";E={$Datastore.Name}}, @{N="Datastore Size (GB)";E={[Math]::Round($Datastore.CapacityGB,0)}}, @{N="Datastore Total Provisioned size (GB)";E={[Math]::Round($Datastore.CapacityGB-$Datastore.FreeSpaceGB+$Datastore.ExtensionData.Summary.Uncommitted/1GB,0)}}, @{N="Datastore Used Space (GB)";E={[Math]::Round($Datastore.CapacityGB-$Datastore.FreeSpaceGB,0)}} } } } }
Regards, Robert
Thanks for the reply Rob, just came back from the long weekend 😉
two things, is there any reason why the result is always showing zero in the DS Size and used space ?
also I need to get the result in CSV format so that I can sort it based on the most over provisoned DS if possible.
Cheers !
Which PowerCLI version are you using ?
Get-PowerCLIVersion
The CapacityGB and FreeSpaceGB were introduced only recently.
To get the result in a CSV file, change the last line to
} | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here it is Luc:
Thanks for the suggestion.
Since you're on a pre-5 version, do it like this
Get-VM | ForEach-Object { if ($_) { $vm = $_
$vm | Get-Datastore | ForEach-Object { if ($_) { $Datastore = $_
"" | Select-Object -Property @{N="VM name";E={$vm.Name}},
@{N="Datastore Name";E={$Datastore.Name}},
@{N="Datastore Size (GB)";E={[Math]::Round($Datastore.CapacityMB/1KB,0)}},
@{N="Datastore Total Provisioned size (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB+$Datastore.ExtensionData.Summary.Uncommitted/1GB,0)}},
@{N="Datastore Used Space (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB,0)}} } } } } | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script is awesome :)...anyone knows how to also include the "provisionedspacegb" property into the output ? meaning the vmdk total space besides the VM name ?
i tried the harddisks (capacityGB) attribute, but im having a hardtime adding that into the output..
Thanks
Martin
The following script adds the ProvisionedSpaceGB property to the output of Luc's script:
Get-VM | ForEach-Object { if ($_) { $vm = $_ $vm | Get-Datastore | ForEach-Object { if ($_) { $Datastore = $_ "" | Select-Object -Property @{N="VM name";E={$vm.Name}}, @{N="ProvisionedSpaceGB";E={$vm.ProvisionedSpaceGB}}, @{N="Datastore Name";E={$Datastore.Name}}, @{N="Datastore Size (GB)";E={[Math]::Round($Datastore.CapacityMB/1KB,0)}}, @{N="Datastore Total Provisioned size (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB+$Datastore.ExtensionData.Summary.Uncommitted/1GB,0)}}, @{N="Datastore Used Space (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB,0)}} } } } }
Thanks !...i got it working after some more coffee
i have to tweak the output a bit, so i can feed Cacti for proper reporting
Thanks again for the quick reply
thanks for the assistance guys !
This is awesome, I'm trying to -format table but I'm not able to get it right, I got errors, is it possible to "format table" this kind of report?
The Foreach loop doesn't place anything on the pipeline.
You can use the Call operator (&) as a bypass.
&{
#
# The original script
#
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD. If i don't put the & at the beginning of the script it seems to run but cannot see three columns.
If I put the & at the beggining of the scripts I get an error.
Get-VM | ForEach-Object &{
if ($_)
{
$vm = $_
$vm | Get-Datastore | ForEach-Object {
if ($_)
{
$Datastore = $_
"" | Select-Object -Property @{N="VM name";E={$vm.Name}},
@{N="ProvisionedSpaceGB";E={$vm.ProvisionedSpaceGB}},
@{N="Datastore Name";E={$Datastore.Name}},
@{N="Datastore Size (GB)";E={[Math]::Round($Datastore.CapacityMB/1KB,0)}},
@{N="Datastore Total Provisioned size (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB+$Datastore.ExtensionData.Summary.Uncommitted/1GB,0)}},
@{N="Datastore Used Space (GB)";E={[Math]::Round(($Datastore.CapacityMB-$Datastore.FreeSpaceMB)/1KB,0)}}
}
}
}
} | format-table -autosize
I get an "Ampersand not allowed: The & operator is reserved"...
If I ignore the &, and just type | format-table -autosize > c:\something.txt, the file is generated but there's a legend at the beginning of the file telling me WARNING: 3 columns do not fit into the display and were removed.
No luck trying to exporting to csv.
Thanks once again!
That first line should be
&{ Get-VM | ForEach-Object
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah.
Now we are talking :smileygrin:
Good, now I'm going to do an attempt of troubleshooting to see why the other 3 columns are not exported to csv.
Thanks!
If you want to export the results to a file, there is no need to use the Format-Table, which is intended for console output.
Try using an Export-Csv, and check in there if all the columns are present
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
lol, I was going to update the post with that, no need of format-table when exporting to csv.
Thanks!