VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

Report to list vm name disk(s) name disk capacity and used space


Hi

Does any one have a script to list the following:

vm name disk(s) name disk capacity and used space

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The ForEach statement doesn't place any objects on the pipeline.

You can achieve that by using the call operator, like this

$vm = gc vm.txt

&{ForEach ($VM in (Get-VM -Name $vm)){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath,
@{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},
@{N="Free Space(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},
@{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}} |

Export-Csv C:\report.csv -NoTypeInformation -UseCulture

You are aware that this will only provide information about the partitions in the guest OS, nothing about the virtual disk(s) attached to the VM ?


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this yadr – A vdisk reporter ?


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

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

Almost but I need each drive letter instead of Hard Disk1, Hard Disk2, etc...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ah, but that might be a problem.

There is no fool-proof method to determine which VirtualDisk corresponds with which guest OS partition.

For example, you can have a vdisk that holds 2 or more guest OS partitions.

Afaik there is no way to make the link between the vdisk and the partitions on it Smiley Sad


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

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

I think I understand what you are saying.

Maybe I didn't eplain what I needed correctly but I found something that might serve my purpose but I can't seem to export the data to a csv file:

$vm = gc vm.txt


ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath,
@{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},
@{N="Free Space(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},
@{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The ForEach statement doesn't place any objects on the pipeline.

You can achieve that by using the call operator, like this

$vm = gc vm.txt

&{ForEach ($VM in (Get-VM -Name $vm)){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath,
@{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},
@{N="Free Space(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},
@{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}} |

Export-Csv C:\report.csv -NoTypeInformation -UseCulture

You are aware that this will only provide information about the partitions in the guest OS, nothing about the virtual disk(s) attached to the VM ?


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

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

It's working good now with the exception that it's getting all of the vm instead of those listed in the vm.txt.

Am I using the Get-Content cmdlet wrong?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, I took your code as-is, but the ForEach loop was not correct.

I updated the script above (the Name parameter on the Get-VM)


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

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

That was it.

As always Luc Thanks!

0 Kudos