VMware Cloud Community
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Report for Capacity planning at cluster level

Hi All,

We are facing trouble for monthly reporting of capacity in Vmware.

Need script for information like cluster level capacity report on both ESXI host and Datastore for multiple Vcentres

If there is any script to get below output or any similair output like below Please let me know

     pastedImage_1.png

         pastedImage_0.png

Need modification on this script to get above data

{foreach($vm in Get-VM){

Get-Datastore -RelatedObject $vm |

Select @{N='Cluster';E={Get-Cluster -VMHost $vm.VMhost | select -ExpandProperty Name}},

  Name,

  @{N='VMName';E={$vm.Name}},

  @{N='NAA';E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

  @{N='Capacity';E={[math]::Round($_.CapacityGB,1)}},

  @{N='Free';E={[math]::Round($_.FreeSpaceGB,1)}}}} |

Export-Csv C:\vm-full-report-2.csv -NoTypeInformation -UseCulture

Thanks,

Karthikeyan Raman.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try these two scripts

Script #1

foreach($vc in $global:DefaultVIServers){

    foreach($cluster in Get-Cluster -Server $vc){

        foreach($esx in Get-VMHost -Location $cluster -Server $vc){

            foreach($vm in Get-VM -Location $esx -Server $vc){

                foreach($hd in Get-HardDisk -VM $vm -Server $vc){

                    $obj = [ordered]@{

                        vCenter = $vc.Name

                        Cluster = $cluster.name

                        VMHost = $esx.Name

                        VMHostRamGB= $esx.MemoryTotalGB

                        VMHostCpu = $esx.NumCpu

                        VM = $vm.Name

                        VMRamGB = $vm.MemoryGB

                        VmCpu = $vm.NumCpu

                        Disk = $hd.Name

                        DiskGB = $hd.CapacityGB

                    }

                    New-Object PSObject -Property $obj

                }

            }

        }

    }

}

Script #2

foreach($vc in $global:DefaultVIServers){

    foreach($dsc in Get-DatastoreCluster -Server $vc){

        foreach($ds in Get-Datastore -Location $dsc -Server $vc){

            foreach($vm in Get-VM -Datastore $ds -Server $vc){

                foreach($hd in Get-HardDisk -VM $vm -Server $vc){

                    $obj = [ordered]@{

                        vCenter = $vc.Name

                        DatastoreCluster = $dsc.name

                        Datastore = $ds.Name

                        CapacityGB = $ds.CapacityGB

                        UsedGB = $ds.CapacityGB - $ds.FreeSpaceGB

                        VM = $vm.Name

                        VMRamGB = $vm.MemoryGB

                        VmCpu = $vm.NumCpu

                        Disk = $hd.Name

                        DiskGB = $hd.CapacityGB

                    }

                    New-Object PSObject -Property $obj

                }

            }

        }

    }

}


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

View solution in original post

Reply
0 Kudos
11 Replies
LucD
Leadership
Leadership
Jump to solution

You have to be a bit more specific on the expected content of some of these columns.
What is supposed to be in the column 'disk' in the 1st table?

And what is the content of the column 'Disk no' in the 2nd table?


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

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Hi LUcd,

The disk mentioned here at last column is VM disk and VM disk number and VM disk space in GB.

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Hi Lucd,

Any script near to the above output is fine. if one or two column missing is also fine.

Please help me.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try these two scripts

Script #1

foreach($vc in $global:DefaultVIServers){

    foreach($cluster in Get-Cluster -Server $vc){

        foreach($esx in Get-VMHost -Location $cluster -Server $vc){

            foreach($vm in Get-VM -Location $esx -Server $vc){

                foreach($hd in Get-HardDisk -VM $vm -Server $vc){

                    $obj = [ordered]@{

                        vCenter = $vc.Name

                        Cluster = $cluster.name

                        VMHost = $esx.Name

                        VMHostRamGB= $esx.MemoryTotalGB

                        VMHostCpu = $esx.NumCpu

                        VM = $vm.Name

                        VMRamGB = $vm.MemoryGB

                        VmCpu = $vm.NumCpu

                        Disk = $hd.Name

                        DiskGB = $hd.CapacityGB

                    }

                    New-Object PSObject -Property $obj

                }

            }

        }

    }

}

Script #2

foreach($vc in $global:DefaultVIServers){

    foreach($dsc in Get-DatastoreCluster -Server $vc){

        foreach($ds in Get-Datastore -Location $dsc -Server $vc){

            foreach($vm in Get-VM -Datastore $ds -Server $vc){

                foreach($hd in Get-HardDisk -VM $vm -Server $vc){

                    $obj = [ordered]@{

                        vCenter = $vc.Name

                        DatastoreCluster = $dsc.name

                        Datastore = $ds.Name

                        CapacityGB = $ds.CapacityGB

                        UsedGB = $ds.CapacityGB - $ds.FreeSpaceGB

                        VM = $vm.Name

                        VMRamGB = $vm.MemoryGB

                        VmCpu = $vm.NumCpu

                        Disk = $hd.Name

                        DiskGB = $hd.CapacityGB

                    }

                    New-Object PSObject -Property $obj

                }

            }

        }

    }

}


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

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Thanks for the script Lucid,

Im editing as per my need

Thanks a lot lucid u r awesome Really great

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Script 1 succesfully passed..

Add-PSSnapin VMware.VimAutomation.Core

Remove-Item "C:\report.csv"         

      

$vCenterServerName = "vc1","vc2"

foreach($vcenter in $vCenterServerName){

connect-viserver -server $vcenter

$objects = @()

    foreach($cluster in (Get-Cluster -Server $vcenter) ){

        foreach($esx in (Get-VMHost -Location $cluster -Server $vcenter)){

            foreach($vm in (Get-VM -Location $esx -Server $vcenter)){

                foreach($hd in (Get-HardDisk -VM $vm -Server $vcenter)){

                        $obj = "" | select vCenter , Cluster , VMHost , VMHostRamGB , VMHostCpu , VM , VMRamGB , VmCpu , Disk , DiskGB

                        $obj.vCenter = $vcenter

                        $obj.Cluster = $cluster.name

                        $obj.VMHost = $esx.Name

                        $obj.VMHostRamGB= $esx.MemoryTotalGB

                        $obj.VMHostCpu = $esx.NumCpu

                        $obj.VM = $vm.Name

                        $obj.VMRamGB = $vm.MemoryGB

                        $obj.VmCpu = $vm.NumCpu

                        $obj.Disk = $hd.Name

                        $obj.DiskGB = $hd.CapacityGB

                        $objects += $obj

                    }

                }

            }

        }$objects | Export-Csv -Append  -Path "C:\report.csv"

         disconnect-viserver -server $vcenter -Confirm:$false  

    }

script 2 continuously getting failed

The script didn't throws any error

The script able to connect to Vc

and provides 0b file

Add-PSSnapin VMware.VimAutomation.Core

Remove-Item "C:\Datastorereport.csv"         

      

$vCenterServerName = "vc1" , "vc2"

foreach($vcenter in $vCenterServerName){

connect-viserver -server $vcenter

$objects = @()

    foreach ( $dsc in Get-DatastoreCluster -server $vcenter){

        foreach($ds in Get-Datastore -Location $dsc -server $vcenter){

            foreach($vm in Get-VM -Datastore $ds -server $vcenter){

                foreach($hd in Get-HardDisk -VM $vm -server $vcenter){

                        $obj = "" | select vCenter , DatastoreCluster , Datastore, CapacityGB , VMRamGB , VmCpu , UsedGB , VM , Disk , DiskGB

                        $obj.vCenter = $vcenter

                        $obj.DatastoreCluster = $dsc.name

                        $obj.Datastore = $ds.Name

                        $obj.CapacityGB = $ds.CapacityGB

                        $obj.UsedGB = $ds.CapacityGB - $ds.FreeSpaceGB

                        $obj.VM = $vm.Name

                        $obj.VMRamGB = $vm.MemoryGB

                        $obj.VmCpu = $vm.NumCpu

                        $obj.Disk = $hd.Name

                        $obj.DiskGB = $hd.CapacityGB

                        $objects += $obj

                    }

                 

                }

            }

        }$objects | Export-Csv -Append -Path "C:\Datastorereport.csv"

         disconnect-viserver -server $vcenter -Confirm:$false

    }

Please let me know do i need to change anything

i guess the issues is with $dsc and $ds

Please help me to resolve the issue

LucD
Leadership
Leadership
Jump to solution

To start with, you could check if there are DatastoreClusters.

Just do a Get-DatastoreCluster from the PowerCLI prompt.


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

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Thanks a Lot

Hmm sorry i tried in my test environment where no clusters are available.

If datastore is available its working fine.

I have one more query, if the datastores not in the datastores cluster will also get reported

The script will be great and complete

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, the current script only lists datastores that are in a datastorecluster.


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

Reply
0 Kudos
KarthikeyanRam1
Contributor
Contributor
Jump to solution

Hi Lucd,

If there any way to report datastores not in cluster and append it to the csv output of above script.

It will be realy helpful

If possible please share me the script to report only the datastores not in cluster

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

foreach($vc in $global:DefaultVIServers){

    foreach($ds in Get-Datastore -Server $vc){

        foreach($vm in Get-VM -Datastore $ds -Server $vc){

            foreach($hd in Get-HardDisk -VM $vm -Server $vc){

                $obj = [ordered]@{

                    vCenter = $vc.Name

                    Datastore = $ds.Name

                    DatastoreCluster = Get-DatastoreCluster -Datastore $DS -ErrorAction SilentlyContinue | sELECT -ExpandProperty Name

                    CapacityGB = $ds.CapacityGB

                    UsedGB = $ds.CapacityGB - $ds.FreeSpaceGB

                    VM = $vm.Name

                    VMRamGB = $vm.MemoryGB

                    VmCpu = $vm.NumCpu

                    Disk = $hd.Name

                    DiskGB = $hd.CapacityGB

                }

                New-Object PSObject -Property $obj

            }

        }

    }

}


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

Reply
0 Kudos