I am working on a script to help get us a few things for capacity plannings as much as just weekly status of our VM's. I feel kinda comfortable when I just have to do a quick one liner for some basic information and there are actually a lot of one liners I have come across. However i'm stuck on when it comes to trying to build a report that I can push to a CSV format to get all the data I'm looking for and seem to be having a hard time understanding how the build process works for getting a concise capacity report.
The other day some one asked for all of the associated drives for our cluster. Well I know I can use "Get-cluster" to get all of our different clusters, the use "Get-Cluster clusterName | Get-VMHost" to get all of the associated ESX host of the cluster. But what I wanted to try to do was break it out a bit more:
Cluster Name:
ESX Host Nmae -
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
Totals cpu memory Total Disk Usage
ESX Host Nmae -
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
Totals cpu memory Total Disk Usage
ESX Host Nmae -
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
VM cpu memory Disk C: Disk 😧 Sub-Total Disk Usage
Totals cpu memory Total Disk Usage
What I had to do was a bunch of one liners because I could not create a full report/script to get what I was after.
get-cluster clusterName | Get-VMHost - got me my ESX Host
$report = get-vmhost vmhostESXHost | get-vm - listed my VM's
I found a one liner to get me total HD utilitation:
$report = get-vmhost fsaptcpesx007.fsa.mrd | get-vm
$report | Select Name,@{N="HD Used (GB)";E={[math]::Round(($_.Guest.Disks | %{ $_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum |
Select -ExpandProperty Sum),1)}}
Then I would use:
$vm = get-vm vmGuest
$vm.guest.disks
and this would give me the break down of the drives.
My first hope is to get a report to get this info but my biggest request is to figure out how this gets done in a report/script. I just got a subscription to a sight to help and I did see a book i'm hoping to purchase. I do have some experience with HTML and PHP but it's not really translating easily to Powershell/PowerCLI. I'll keep at it for sure, but just know there has to be a good reference to help put it together.
Any suggestions/advice is greatly appreciated.
Cheers,
Well, I'm getting closer. I kept trying different ways to get the VM Name along with the associated drives and came across this script:
$(foreach ( $cluster in "Linux_NonProd_Cluster", "Linux_Production_Cluster") { get-view -SearchRoot (get-cluster $cluster).id -viewtype VirtualMachine -Filter @{"Summary.Runtime.PowerState"="poweredOn";"Config.Template"="False"} | % {$esxhost=(get-view ($_.Summary.Runtime.Host)).name;$vmname=$_.Name;$_.Guest.Disk | select @{N="VMName";E={$vmname}},DiskPath,@{N="CapacityGB"; E={[Math]::Round($_.Capacity/1GB,2)} },@{N="FeeSpaceGB";E={[Math]::Round($_.FreeSpace/1GB,2)}},@{N="Cluster";E={$cluster} },@{N="Host";E={$esxhost} } } }) | Export-Csv "c:\scripts\schtasks\ReportVMsDiskUsageLinux.csv" -NoTypeInformation
Script credit to - Grzegorz Kulikowski
This has given me a great starting point, bad part is I don't understand the process yet. but I did want to share this in case someone else needs to find the VM name with associated drives with Path /CapacityGB and FreeSpaceGB.
Unfortunately they have asked that I also acquire this information for our Physical servers and hoping to find a similar powershell to create the same data.
I'll keep plugging along and updating thread with my updates.