Automation

 View Only
Expand all | Collapse all

Report for Capacity planning at cluster level

  • 1.  Report for Capacity planning at cluster level

    Posted May 25, 2017 12:40 AM

    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

        

            

    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.



  • 2.  RE: Report for Capacity planning at cluster level

    Posted May 25, 2017 06:53 AM

    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?



  • 3.  RE: Report for Capacity planning at cluster level

    Posted May 25, 2017 02:24 PM

    Hi LUcd,

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



  • 4.  RE: Report for Capacity planning at cluster level

    Posted May 27, 2017 03:11 PM

    Hi Lucd,

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

    Please help me.



  • 5.  RE: Report for Capacity planning at cluster level
    Best Answer

    Posted May 27, 2017 09:27 PM

    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

                    }

                }

            }

        }

    }



  • 6.  RE: Report for Capacity planning at cluster level

    Posted May 28, 2017 01:41 AM

    Thanks for the script Lucid,

    Im editing as per my need

    Thanks a lot lucid u r awesome Really great



  • 7.  RE: Report for Capacity planning at cluster level

    Posted May 28, 2017 05:00 PM

    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



  • 8.  RE: Report for Capacity planning at cluster level

    Posted May 28, 2017 05:25 PM

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

    Just do a Get-DatastoreCluster from the PowerCLI prompt.



  • 9.  RE: Report for Capacity planning at cluster level

    Posted May 28, 2017 08:48 PM

    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



  • 10.  RE: Report for Capacity planning at cluster level

    Posted May 29, 2017 04:32 AM

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



  • 11.  RE: Report for Capacity planning at cluster level

    Posted Jun 04, 2017 02:51 AM

    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



  • 12.  RE: Report for Capacity planning at cluster level

    Posted Jun 04, 2017 07:26 AM

    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

                }

            }

        }

    }