Hi
Does any one have a script to list the following:
vm name disk(s) name disk capacity and used space
Thanks
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
Something like this yadr – A vdisk reporter ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Almost but I need each drive letter instead of Hard Disk1, Hard Disk2, etc...
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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)}})}
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
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?
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
That was it.
As always Luc Thanks!