I have a difficult question to ask. I want to find out the total of the Virtual disks used by my Virtual machines in 2 specific clusters. Is that possible to do. I want to include any raw disks as well in the VM. So if possible I would list all VM's and their virtual disks (including raw disks) and then at the bottom there would be a grand total of all the virtual disks used and only apply to virtual machines in specific clusters and the total been in TB's if possible.
Can anyone advise
Thanks for the script.
When I run it, it lists all the VM's and their capacity in KB, but when it gets to do the total in TB it gives the following error message:
ForEach-object : cannot bind parameter 'process'. Cannot convert the "0" value of type "System.Int32" to type "system.management.automation.scriptBlock"
It then gives 0 TB's.
Does the script need to be modified, especially where it does the total part.
Thanks
Running on my setup it works that is strange that it throws that error for you. Try running it line by line in the VIPowershell. If you can post what it does during that proccess that would be great.
For the list of all harddisks you can use the script from .
Although ProPenguin his script to calculate the total disk size works for me, I changed his script a little so it does the formatting in the last line:
#Get Sum of all Disks in TBs $TotalDisk = 0 Get-VM | Get-HardDisk | ForEach-Object {$TotalDisk += $_.CapacityKB} $TotalDisk = $TotalDisk/1024/1024/1024 "Total disk size: {0:f2} TB" -f $TotalDisk
Regards, Robert
Did you figure this out?
Robert,
I have added
$vmcount = get-vm | measure-object | select -property count
"average size: " $totaldisk/$vmcount.count
To get the average size, but it's not working, throwing an
Unexpected token 'totaldisk' in expression or statement.
At :line:7 char:19
+ "avg: " $totaldisk/ <<<< $vmcount.count
What am I doing wrong?
Thanks
You have to use the -format operator which will result in a string that PS knows how to display
#Get Sum of all Disks in TBs $TotalDisk = 0 Get-VM | Get-HardDisk | ForEach-Object {$TotalDisk += $_.CapacityKB} $TotalDisk = $TotalDisk/1024/1024/1024 "Total disk size: {0:f2} TB" -f $TotalDisk $vmcount = get-vm | measure-object | select -property count "average size: {0:f2}" -f ($totaldisk/$vmcount.count)
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Any Luck?